AdventOfCode/memory_alloc.rb
2017-12-06 19:02:14 +01:00

23 lines
428 B
Ruby

input = "5 1 10 0 1 7 13 14 3 12 8 10 7 12 0 6".split("\t").map(&:to_i)
snapshots = []
res = 0
while not snapshots.include? input do
snapshots << input.dup
max_val = input.max
idx = input.index max_val
input[idx] = 0
while max_val > 0 do
idx += 1
input[idx % input.length] += 1
max_val -= 1
end
res += 1
end
puts res
cycle_first = snapshots.find_index(input)
puts cycle_first
puts res - cycle_first