aboutsummaryrefslogtreecommitdiff
path: root/2022/01/solve.py
diff options
context:
space:
mode:
authorMarvin Borner2022-12-01 06:24:25 +0100
committerMarvin Borner2022-12-01 06:24:25 +0100
commit0cb7f8aa21366172d1cc9aaa4ff1ce2ced21fa37 (patch)
treee7156ce204914c3e333c569c59c2709212318ae6 /2022/01/solve.py
parentce4f7000ea6169989819f99ab72c1194eb458a34 (diff)
i'll use input downloaders from now on
i hate everyone
Diffstat (limited to '2022/01/solve.py')
-rw-r--r--2022/01/solve.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/2022/01/solve.py b/2022/01/solve.py
new file mode 100644
index 0000000..de9aea8
--- /dev/null
+++ b/2022/01/solve.py
@@ -0,0 +1,29 @@
+data = [block.split("\n") for block in open("input").read().split("\n\n")]
+
+# i don't know list comprehension
+
+def part1():
+ res = 0
+ for block in data:
+ sum = 0
+ for calory in block:
+ if len(calory) > 0:
+ sum += int(calory)
+ if sum > res:
+ res = sum
+ return res
+
+def part2():
+ top3 = [0,0,0]
+ for block in data:
+ s = 0
+ for calory in block:
+ if len(calory) > 0:
+ s += int(calory)
+ if s > min(top3):
+ top3.remove(min(top3))
+ top3.append(s)
+ return sum(top3)
+
+print(f"Part 1: {part1()}")
+print(f"Part 2: {part2()}")