AdventOfCode/searching_for_nil.rb
2017-12-05 23:33:24 +01:00

27 lines
403 B
Ruby

input = File.read("input_lol").split("\n").map(&:to_i)
i1 = 0
res1 = 0
part1 = input.dup
while part1[i1] != nil do
curr1, part1[i1] =i1 + part1[i1], part1[i1] + 1
i1, res1 = curr1, res1+1
end
puts res1
i2 = 0
res2 = 0
part2 = input.dup
while part2[i2] != nil do
curr2, part2[i2] =i2 + part2[i2], part2[i2] + (if part2[i2] >= 3 then -1 else 1 end)
i2, res2 = curr2, res2+1
end
puts res2