Created
December 7, 2018 18:15
-
-
Save davidkellis/8880c09faa8625504e53f2aea98d79c4 to your computer and use it in GitHub Desktop.
aocday1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ints = File.readlines("input.txt").map(&:to_i) | |
puts ints.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "set" | |
ints = File.readlines("input.txt").map(&:to_i) | |
sum = 0 | |
observations = [sum].to_set | |
while true | |
ints.each do |i| | |
sum += i | |
if observations.include?(sum) | |
puts "sum=#{sum}" | |
exit | |
end | |
observations << sum | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment