File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ require_relative 'day'
2
+
3
+ class Day14 < Day # >
4
+
5
+ # @example
6
+ # day.part1 #=> 136
7
+ def part1
8
+ columns =
9
+ input
10
+ . split ( "\n " )
11
+ . map ( &:chars )
12
+ . transpose # pivot so that each array is a column
13
+ . reject { |column | !column . include? ( "O" ) } # don't bother with columns that don't have rounded rocks
14
+ . map ( &:join ) # make it a string again
15
+ . map { |column |
16
+ column
17
+ . reverse # north is now towards the end of the string
18
+ . split ( "#" , -1 ) # find the stretches between cube rocks, keep trailing empties
19
+ . map { |substring |
20
+ substring . chars . sort . join # roll rocks within stretches
21
+ }
22
+ . join ( "#" ) # put the cubes back in
23
+
24
+ }
25
+ . map { |rolled_column |
26
+ ( 0 ..rolled_column . length )
27
+ . filter_map { |i | i +1 if rolled_column [ i ] == "O" }
28
+ . reduce ( &:+ )
29
+ }
30
+ . reduce ( &:+ )
31
+ end
32
+
33
+ # example
34
+ # day.part2 #=> 'how are you'
35
+ def part2
36
+ end
37
+
38
+ EXAMPLE_INPUT = <<~INPUT
39
+ O....#....
40
+ O.OO#....#
41
+ .....##...
42
+ OO.#O....O
43
+ .O.....O#.
44
+ O.#..O.#.#
45
+ ..O..#O..O
46
+ .......O..
47
+ #....###..
48
+ #OO..#....
49
+ INPUT
50
+ end
You can’t perform that action at this time.
0 commit comments