Skip to content

Commit

Permalink
Year 2018 Day 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tudorpavel committed Oct 27, 2024
1 parent 15229ce commit bc9a4d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 2018/day01.rb
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions 2018/examples/day01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
+1
-2
+3
+1
+1
-2

0 comments on commit bc9a4d8

Please sign in to comment.