AdventOfCode/memory_alloc.rb

23 lines
428 B
Ruby
Raw Permalink Normal View History

2017-12-06 18:02:14 +00:00
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