Skip to content

Commit a478e33

Browse files
author
Robb Kidd
committed
day 14, part 1
wheeee naive repeatative mapping and string transforms! Almost certainly not set up for success in part 2! ᕕ( ᐛ )ᕗ
1 parent 232ce12 commit a478e33

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

2023/ruby/day14.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

0 commit comments

Comments
 (0)