diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-12-07 12:57:36 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-12-07 12:57:36 +0000 |
commit | d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56 (patch) | |
tree | 999464f801480565733c5223b020b2d762140b00 /2.py | |
download | aoc2022-d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56.tar.gz aoc2022-d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56.tar.xz aoc2022-d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56.zip |
days 1-7
Diffstat (limited to '2.py')
-rw-r--r-- | 2.py | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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)) |