aboutsummaryrefslogtreecommitdiff
path: root/day01/part2
blob: 506d995f4331647d41b75ea1c6330846c789ce17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env ruby

input = $stdin.readlines.map(&:to_i)

lf = 0
posifreq = [true]
negifreq = []

loop do
	input.each do |i|
		lf += i
		if  lf >= 0 && posifreq[lf]  ||
        lf < 0  && negifreq[-lf]
			puts lf
			exit
		end
    if lf >= 0
  		posifreq[lf] = true
    else
      negifreq[-lf] = true
    end
	end
end