aboutsummaryrefslogtreecommitdiff
path: root/2020/09/puzzle-2.py
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-10-29 23:02:39 +0200
committerThomas Voss <thomasvoss@live.com> 2021-10-29 23:02:39 +0200
commite7c9108b95e39d7ea5a29ae06d619c4727f11027 (patch)
tree237261eef3afd0720be77dbcbb9599fa66a24b67 /2020/09/puzzle-2.py
Initial commit
Diffstat (limited to '2020/09/puzzle-2.py')
-rwxr-xr-x2020/09/puzzle-2.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/2020/09/puzzle-2.py b/2020/09/puzzle-2.py
new file mode 100755
index 0000000..8833f50
--- /dev/null
+++ b/2020/09/puzzle-2.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+import numpy as np
+
+
+def main() -> None:
+ goal = 138879426
+ with open("input", "r") as f:
+ nums = np.array(list(map(int, f.readlines())), dtype=int)
+
+ lp = 0
+ up = 1
+
+ while (x := sum(nums[lp : up + 1])) != goal:
+ if x > goal:
+ up -= 1
+ lp += 1
+ elif x < goal:
+ up += 1
+
+ sorted = np.sort(nums[lp : up + 1])
+ print(sorted[0] + sorted[-1])
+
+
+if __name__ == "__main__":
+ main()