From f248d715d4a3c19f84475fcb6d076a6874fcf7e0 Mon Sep 17 00:00:00 2001 From: Brian Chu Date: Sat, 4 Dec 2021 12:49:24 -0800 Subject: commit for days 1 through 4 --- day1.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 day1.py (limited to 'day1.py') 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) -- cgit 1.4.1-2-gfad0