-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathday02.py
executable file
·79 lines (64 loc) · 1.3 KB
/
day02.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
from utils.all import *
advent.setup(2022, 2)
DEBUG = 'debug' in map(str.lower, sys.argv)
if not DEBUG:
fin = advent.get_input()
else:
fin = io.StringIO('''\
A Y
B X
C Z
''')
lines = get_lines(fin); fin.seek(0, 0)
ans = 0
for line in lines:
a, b = line.strip().split()
ab = a + b
if ab == 'AX': # ro ro = dra
ans += 3 + 1
elif ab == 'AY': # ro pa = wi
ans += 6 + 2
elif ab == 'AZ': # ro sci = lose
ans += 0 + 3
elif ab == 'BX': # paper rock = lose
ans += 0 + 1
elif ab == 'BY': # paper paper = dr
ans += 3 + 2
elif ab == 'BZ':
ans += 6 + 3 # paper scis = win
elif ab == 'CX':
ans += 6 + 1 # sci rock = win
elif ab == 'CY':
ans += 0 + 2 # sci pap = lose
elif ab == 'CZ':
ans += 3 + 3 # sci sci = draw
else:
assert ab
# 10851 wrong
advent.print_answer(1, ans)
ans = 0
for line in lines:
a, b = line.strip().split()
ab = a + b
if ab == 'AX': # ro lose
ans += 0 + 3
elif ab == 'AY': # ro dra
ans += 3 + 1
elif ab == 'AZ': # ro wi
ans += 6 + 2
elif ab == 'BX': # paper lose
ans += 0 + 1
elif ab == 'BY': # paper dra
ans += 3 + 2
elif ab == 'BZ':
ans += 6 + 3 # paper wi
elif ab == 'CX':
ans += 0 + 2 # sci lose
elif ab == 'CY':
ans += 3 + 3 # sci dra
elif ab == 'CZ':
ans += 6 + 1 # sci win
else:
assert ab
advent.print_answer(2, ans)