diff --git a/2018/day01.rb b/2018/day01.rb new file mode 100644 index 0000000..8bffc18 --- /dev/null +++ b/2018/day01.rb @@ -0,0 +1,16 @@ +nums = STDIN.read.split("\n").map(&:to_i) +puts nums.sum + +def part2(nums) + seen = Set.new + sum = 0 + loop do + nums.each do |num| + return sum if seen.include?(sum) + seen.add(sum) + sum += num + end + end +end + +puts part2(nums) diff --git a/2018/examples/day01.txt b/2018/examples/day01.txt new file mode 100644 index 0000000..e5c174f --- /dev/null +++ b/2018/examples/day01.txt @@ -0,0 +1,6 @@ ++1 +-2 ++3 ++1 ++1 +-2