aboutsummaryrefslogtreecommitdiff
path: root/2022/03/puzzle-1.py
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-12-03 06:29:07 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-12-03 06:29:07 +0100
commit3be62b50f80c1d67d9867775242c33e88266fec8 (patch)
tree76181d3c464612e7b5d000a68cd33dc7b9ecf851 /2022/03/puzzle-1.py
parent3cc1430b049cd5cd713fcb2e8bfc2ca14ac1502f (diff)
Add 2022 day 3 solutions
Diffstat (limited to '2022/03/puzzle-1.py')
-rwxr-xr-x2022/03/puzzle-1.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/2022/03/puzzle-1.py b/2022/03/puzzle-1.py
new file mode 100755
index 0000000..713e282
--- /dev/null
+++ b/2022/03/puzzle-1.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python3
+
+def cut(s: str) -> (str, str):
+ n = len(s) // 2
+ return s[:n], s[n:]
+
+
+def main() -> None:
+ with open("input", "r") as f:
+ data = f.readlines()
+
+ acc = 0
+ for line in data:
+ car, cdr = cut(line)
+ for c in car:
+ if cdr.find(c) != -1:
+ if "a" <= c <= "z":
+ acc += ord(c) - ord("a") + 1
+ else:
+ acc += ord(c) - ord("A") + 27
+ break
+
+ print(acc)
+
+
+if __name__ == "__main__":
+ main()