From fe75c10e350743a1c078f065d69556fecf825ca5 Mon Sep 17 00:00:00 2001 From: nekineki Date: Sun, 11 Dec 2022 14:47:27 +0100 Subject: move files around, update paths --- 2022/day02.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 2022/day02.py (limited to '2022/day02.py') diff --git a/2022/day02.py b/2022/day02.py new file mode 100755 index 0000000..b499db3 --- /dev/null +++ b/2022/day02.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +import math +import time + +score1 = 0 +score2 = 0 + +# filename = "in/day02.ref" +filename = "in/day02.pzl" +with open(filename) as f: + for line in f: + line = line.strip() + abc, xyz = line[0], line[2] + + if abc == 'A': + abc = 1 + elif abc == 'B': + abc = 2 + elif abc == 'C': + abc = 3 + else: + print('ERROR') + + if xyz == 'X': + xyz = 1 + elif xyz == 'Y': + xyz = 2 + elif xyz == 'Z': + xyz = 3 + else: + print('ERROR') + + s1 = 0 + if abc == xyz: + print('draw') + s1 = 3 + xyz + # elif ((xyz + 1)%3) + 1 == abc: + elif abc%3 + 1 == xyz: + print('win') + s1 = 6 + xyz + else: + print('lose') + s1 = 0 + xyz + print('s1', s1) + score1 += s1 + + if xyz == 1: + # lose + s2 = 0 + (abc-1 + 2)%3 + 1 + elif xyz == 2: + # draw + s2 = 3 + abc + elif xyz == 3: + # win + s2 = 6 + (abc-1 + 1)%3 + 1 + print('s2', s2) + score2 += s2 + + print('score1', score1) + print('score2', score2) + -- cgit v1.2.3