aboutsummaryrefslogtreecommitdiff
path: root/2022/03/solve.py
diff options
context:
space:
mode:
authorMarvin Borner2022-12-03 06:11:39 +0100
committerMarvin Borner2022-12-03 06:11:39 +0100
commitfc738bf428da8381136855b8de478349ea239e13 (patch)
tree4437bd6ec5be29d7e34db5f3f6055ab89f6825a1 /2022/03/solve.py
parenta1819f735e5939bad4f92ca90fd8163f4723eb31 (diff)
lesgo
Diffstat (limited to '2022/03/solve.py')
-rw-r--r--2022/03/solve.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/2022/03/solve.py b/2022/03/solve.py
new file mode 100644
index 0000000..68b58c2
--- /dev/null
+++ b/2022/03/solve.py
@@ -0,0 +1,30 @@
+data = [dat.strip() for dat in open("input").read().split("\n") if dat != '']
+
+def part1():
+ res = 0
+
+ for line in data:
+ comp1 = list(line[len(line)//2:])
+ comp2 = list(line[:len(line)//2])
+ inter = list(set(comp1).intersection(comp2))[0]
+ if inter.islower():
+ res += ord(inter) - ord('a') + 1
+ elif inter.isupper():
+ res += ord(inter) - ord('A') + 27
+
+ return res
+
+def part2():
+ res = 0
+
+ for i in range(0, len(data), 3):
+ common = list(set(data[i]).intersection(data[i+1]).intersection(data[i+2]))[0]
+ if common.islower():
+ res += ord(common) - ord('a') + 1
+ elif common.isupper():
+ res += ord(common) - ord('A') + 27
+
+ return res
+
+print(f"Part 1: {part1()}")
+print(f"Part 2: {part2()}")