aboutsummaryrefslogtreecommitdiff
path: root/2022/02/solve.py
diff options
context:
space:
mode:
authorMarvin Borner2022-12-02 06:41:40 +0100
committerMarvin Borner2022-12-02 06:41:40 +0100
commit0c2933d2432b73cca27fc01f0fa67f0bd96d66ab (patch)
tree320985dcc3cc005e84671b75a708050669414848 /2022/02/solve.py
parent7bdd889035089706c4c3219f29941501af0259b6 (diff)
ez
Diffstat (limited to '2022/02/solve.py')
-rw-r--r--2022/02/solve.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/2022/02/solve.py b/2022/02/solve.py
new file mode 100644
index 0000000..00d4a5f
--- /dev/null
+++ b/2022/02/solve.py
@@ -0,0 +1,40 @@
+data = [dat.split(" ") for dat in open("input").read().split("\n") if dat != '']
+
+# X Y Z = Rock Paper Scissors
+# A B C = Rock Paper Scissors
+
+def part1():
+ res = 0
+
+ choice=[1,2,3]
+ mat = [3,6,0]
+ factors = [1, 0, 2]
+ mat = [0,3,6]
+ for line in data:
+ res += choice[ord(line[1]) - ord("X")]
+ factor = factors[ord(line[0]) - ord("A")]
+ rot = mat[factor:] + mat[:factor]
+ res += rot[ord(line[1]) - ord("X")]
+
+ return res
+
+# X Y Z = lose draw win
+# 1 2 3 = Rock Paper Scissors
+# A B C = Rock Paper Scissors
+
+def part2():
+ res = 0
+
+ choice = [0,3,6]
+ mat = [3,1,2]
+
+ for line in data:
+ res += choice[ord(line[1]) - ord("X")]
+ factor = ord(line[0]) - ord("A")
+ rot = mat[factor:] + mat[:factor]
+ res += rot[ord(line[1]) - ord("X")]
+
+ return res
+
+print(f"Part 1: {part1()}")
+print(f"Part 2: {part2()}")