AoC2018/day01/solution.rb

16 lines
325 B
Ruby
Raw Normal View History

2021-11-10 14:50:43 +00:00
#!/bin/env ruby
# Sum all numbers in the text file.
# Part 1
2021-11-10 16:44:37 +00:00
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]