summaryrefslogtreecommitdiff
path: root/2022/day02.py
diff options
context:
space:
mode:
Diffstat (limited to '2022/day02.py')
-rwxr-xr-x2022/day02.py62
1 files changed, 62 insertions, 0 deletions
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)
+