AoC2018/day01/solution.rb

16 lines
325 B
Ruby

#!/bin/env ruby
# Sum all numbers in the text file.
# Part 1
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]