Add day 10 and day 9 solutions.
This commit is contained in:
36
day9.cr
Normal file
36
day9.cr
Normal file
@@ -0,0 +1,36 @@
|
||||
require "./common.cr"
|
||||
|
||||
lines = File.read("day9_input").split "\n"
|
||||
lines.pop
|
||||
|
||||
players = 463
|
||||
last_points = 400
|
||||
|
||||
marbles = [ 0 ]
|
||||
scores = Array(Int32).new(players, 0)
|
||||
player = 0
|
||||
pos = 0
|
||||
|
||||
(last_points).times do |i|
|
||||
i = i + 1
|
||||
if (i % 23 == 0)
|
||||
delete_at = (pos - 7 - marbles.size) % marbles.size
|
||||
|
||||
puts "current: #{i}"
|
||||
puts "popping: #{marbles[delete_at]}"
|
||||
scores[player] += i
|
||||
scores[player] += marbles[delete_at]
|
||||
|
||||
pos = delete_at
|
||||
marbles.delete_at delete_at
|
||||
else
|
||||
at = (pos + 2) % marbles.size
|
||||
marbles.insert at, i
|
||||
pos = marbles.index(i).not_nil!
|
||||
end
|
||||
|
||||
puts marbles
|
||||
player = (player + 1) % players
|
||||
end
|
||||
|
||||
puts scores.max
|
||||
Reference in New Issue
Block a user