summaryrefslogtreecommitdiffstats
path: root/2.py
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2022-12-07 12:57:36 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2022-12-07 12:57:36 +0000
commitd9a97e9bf28cf91f1a7e57f1298b7c742e25ed56 (patch)
tree999464f801480565733c5223b020b2d762140b00 /2.py
downloadaoc2022-d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56.tar.gz
aoc2022-d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56.tar.xz
aoc2022-d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56.zip
days 1-7
Diffstat (limited to '2.py')
-rw-r--r--2.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/2.py b/2.py
new file mode 100644
index 0000000..abcd27f
--- /dev/null
+++ b/2.py
@@ -0,0 +1,18 @@
+with open('2.in') as f:
+ inp = []
+ for line in f:
+ a, b = line.rstrip().split()
+ inp.append((ord(a) - ord('A'), ord(b) - ord('X')))
+def shape_score(me):
+ return me + 1
+def outcome_score(opp, me):
+ return (3 - opp + me + 1) % 3 * 3
+def p1(opp, me):
+ return shape_score(me) + outcome_score(opp, me)
+print(sum(p1(a, b) for a, b in inp))
+def shape_for_outcome(opp, outcome):
+ return (3 + opp + outcome + 2) % 3
+def p2(opp, outcome):
+ me = shape_for_outcome(opp, outcome)
+ return p1(opp, me)
+print(sum(p2(a, b) for a, b in inp))