This commit is contained in:
Alexander Munch-Hansen 2017-12-06 19:02:14 +01:00
parent 4e28fae0f5
commit 0581fd9c88

22
memory_alloc.rb Normal file
View File

@ -0,0 +1,22 @@
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