solved part 2

master
s00ner 8 months ago
parent d62dda2921
commit 8bd7ab3b2f
  1. 12
      day01/solution.rb

@ -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]

Loading…
Cancel
Save