AdventOfCode-2018/day1_2.cr

20 lines
317 B
Crystal

count = { 0 => 1 }
acc = 0
changes = File.read("day1").split("\n")
.select { |it| !it.empty? }
.map(&.to_i)
while true
changes.each do |i|
acc += i
old_count = count[acc]? || 0
new_count = old_count + 1
count[acc] = new_count
if new_count == 2
puts acc
exit
end
end
end