AoC 2018 code.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
325 B

#!/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]