summary refs log tree commit diff stats
path: root/day1.py
blob: 4cfb29280dfe90b4a07dd628c3765e9f8b20e376 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python

curr = None
count = 0

with open("day1.txt") as input:
    for line in input:
        line = int(line)
        if not curr:
            curr = line
            continue
        if line > curr:
            count += 1
        curr = line

print(count)


curr = None
count = 0
with open("day1.txt") as input:
    first = int(next(input))
    second = int(next(input))
    third = int(next(input))
    while True:
        if not curr:
            curr = first + second + third
            continue
        if first + second + third > curr:
            count += 1
        curr = first + second + third
        try:
            first = second
            second = third
            third = int(next(input))
        except StopIteration:
            break

print(count)