37 lines
665 B
Crystal
37 lines
665 B
Crystal
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
|