aboutsummaryrefslogtreecommitdiff
path: root/2021/09/puzzle-1.py
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-12-09 20:34:05 +0100
committerThomas Voss <thomasvoss@live.com> 2021-12-09 20:34:05 +0100
commit1b250dfa1848e81943fa2f70976f8fa4669c8de9 (patch)
tree286b904ccc0283da427661c933ebdfd7199f75ff /2021/09/puzzle-1.py
parente89223eecb7dbb67a45afccfc843b936be3e3efd (diff)
Add day 9 solutions
Diffstat (limited to '2021/09/puzzle-1.py')
-rwxr-xr-x2021/09/puzzle-1.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/2021/09/puzzle-1.py b/2021/09/puzzle-1.py
new file mode 100755
index 0000000..5ab2f45
--- /dev/null
+++ b/2021/09/puzzle-1.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+
+def main() -> None:
+ with open("input", "r", encoding="utf-8") as f:
+ data = list(map(lambda l: [int(n) for n in l.strip()], f.readlines()))
+
+ acc = 0
+ rows = len(data[0])
+ cols = len(data)
+
+ for i in range(cols):
+ for j in range(rows):
+ if (
+ i != 0
+ and data[i - 1][j] <= data[i][j]
+ or i != cols - 1
+ and data[i + 1][j] <= data[i][j]
+ or j != 0
+ and data[i][j - 1] <= data[i][j]
+ or j != rows - 1
+ and data[i][j + 1] <= data[i][j]
+ ):
+ continue
+
+ acc += data[i][j] + 1
+
+ print(acc)
+
+
+if __name__ == "__main__":
+ main()