diff options
author | Brian Chu <brianmchu42@gmail.com> | 2021-12-04 12:49:24 -0800 |
---|---|---|
committer | Brian Chu <brianmchu42@gmail.com> | 2021-12-04 12:49:24 -0800 |
commit | f248d715d4a3c19f84475fcb6d076a6874fcf7e0 (patch) | |
tree | 6d4c3a75be551e16f41bc7fde6002d6b8e407975 /day1.py | |
download | AdventOfCode2021-f248d715d4a3c19f84475fcb6d076a6874fcf7e0.tar.gz |
commit for days 1 through 4
Diffstat (limited to 'day1.py')
-rw-r--r-- | day1.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/day1.py b/day1.py new file mode 100644 index 0000000..4cfb292 --- /dev/null +++ b/day1.py @@ -0,0 +1,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) |