38 lines
540 B
Python
38 lines
540 B
Python
ahand = ("A", "B", "C")
|
|
bhand = ("X", "Y", "Z")
|
|
win_tbl = {
|
|
"A": "B",
|
|
"B": "C",
|
|
"C": "A",
|
|
}
|
|
|
|
defeats_tbl = {
|
|
"A": "C",
|
|
"B": "A",
|
|
"C": "B",
|
|
}
|
|
|
|
|
|
def load(filename):
|
|
with open(filename) as f:
|
|
t = 0
|
|
for l in f:
|
|
a, b = l.rstrip().split(" ")
|
|
|
|
if b == "X":
|
|
h = ahand.index(defeats_tbl[a]) + 1
|
|
t += h
|
|
|
|
elif b == "Y":
|
|
h = ahand.index(a) + 1
|
|
t += h + 3
|
|
|
|
elif b == "Z":
|
|
h = ahand.index(win_tbl[a]) + 1
|
|
t += h + 6
|
|
|
|
return t
|
|
|
|
assert load("demo.txt") == 12
|
|
t = load("data.txt")
|
|
print("Total points: ", t)
|