-
Notifications
You must be signed in to change notification settings - Fork 0
/
day25.rb
43 lines (34 loc) · 959 Bytes
/
day25.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
file = File.open("input.txt")
seafloor = Array.new
file.each_line do |line|
seafloor.push line.chomp!()
end
rowSize = seafloor.size()
colSize = seafloor[0].size()
step = 0
while true
east_seafloor = seafloor.map(&:clone)
(0..rowSize - 1).each do |row|
(0..colSize - 1).each do |col|
if seafloor[row][col] == ">" and seafloor[row][(col + 1) % colSize] == "."
east_seafloor[row][col] = "."
east_seafloor[row][(col + 1) % colSize] = ">"
end
end
end
south_seafloor = east_seafloor.map(&:clone)
(0..rowSize - 1).each do |row|
(0..colSize - 1).each do |col|
if seafloor[row][col] == "v" and east_seafloor[(row + 1) % rowSize][col] == "."
south_seafloor[row][col] = "."
south_seafloor[(row + 1) % rowSize][col] = "v"
end
end
end
step += 1
if (south_seafloor == seafloor)
break
end
seafloor = south_seafloor.map(&:clone)
end
puts "Day 25, part 1: %d" % [step]