summary refs log tree commit diff stats
path: root/day1.py
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2021-12-04 12:49:24 -0800
committerBrian Chu <brianmchu42@gmail.com>2021-12-04 12:49:24 -0800
commitf248d715d4a3c19f84475fcb6d076a6874fcf7e0 (patch)
tree6d4c3a75be551e16f41bc7fde6002d6b8e407975 /day1.py
downloadAdventOfCode2021-f248d715d4a3c19f84475fcb6d076a6874fcf7e0.tar.gz
commit for days 1 through 4
Diffstat (limited to 'day1.py')
-rw-r--r--day1.py39
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)