Skip to content

Commit 7123e68

Browse files
committed
Add 2023 day 14, first part
1 parent 77a560b commit 7123e68

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

2023/day14/day14a

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env ruby
2+
3+
def tilt_up(rock_map)
4+
rock_map.transpose.map do |line_arr|
5+
line = line_arr.join
6+
while line.include?(".O")
7+
line.gsub!(".O", "O.")
8+
end
9+
10+
line.split("")
11+
end.transpose
12+
end
13+
14+
def calculate_load(rock_map)
15+
rock_map.reverse_each.with_index.sum do |line, idx|
16+
line.count { |el| el == "O" } * (idx + 1)
17+
end
18+
end
19+
20+
file = File.open(ARGV[0])
21+
22+
rock_map = file.readlines.map(&:chomp).map(&:chars)
23+
tilted_map = tilt_up(rock_map)
24+
25+
puts calculate_load(tilted_map)

0 commit comments

Comments
 (0)