solved part 2

master
s00ner 2021-11-10 11:44:37 -05:00
parent d62dda2921
commit 8bd7ab3b2f
1 changed files with 11 additions and 1 deletions

View File

@ -2,4 +2,14 @@
# Sum all numbers in the text file.
# Part 1
sum = File.readlines('./input').map { |line| line.to_i)}.sum
sum = File.readlines('./input').map { |line| line.to_i}.sum
# Part 2
numbers = File.readlines('./input').map { |line| line.to_i}
freqs = [0]
numbers.cycle do |num|
freqs.push(freqs[-1] + num)
break if freqs[0..-2].include?(freqs[-1])
end
puts freqs[-1]