We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 77a560b commit 7123e68Copy full SHA for 7123e68
2023/day14/day14a
@@ -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
18
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