Merge other solutions into one file.

This commit is contained in:
2018-12-02 21:34:51 -08:00
parent cf06140366
commit 5ac0c699e5
6 changed files with 50 additions and 53 deletions

20
day1.cr Normal file
View File

@@ -0,0 +1,20 @@
changes = File.read("day1").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