The solutions to advent of code puzzles, year 2018.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
AdventOfCode-2018/day1.cr

20 lines
330 B

changes = File.read("day1_input").split("\n")
.select { |it| !it.empty? }
.map(&.to_i)
puts "Final frequency: #{changes.sum}"
count = { 0 => 1 }
acc = 0
changes.cycle 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