You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
854 B
32 lines
854 B
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import numpy as np
|
|
|
|
def calc_score(game):
|
|
a = ['A', 'B', 'C'].index(game[0])
|
|
b = ['X', 'Y', 'Z'].index(game[1])
|
|
if a == b: return 1 + b + 3
|
|
elif b == ((a-1) % 3): return 1 + b
|
|
else: return 1 + b + 6
|
|
|
|
def calc_moves(game):
|
|
a = ['A', 'B', 'C'].index(game[0])
|
|
o = ['X', 'Y', 'Z'].index(game[1])
|
|
if o == 1: return 1 + a + 3
|
|
elif o == 0: return 1 + ((a - 1) % 3)
|
|
else: return 1 + ((a + 1) % 3) + 6
|
|
|
|
if __name__ == '__main__':
|
|
games = [tuple(line.strip('\n').split(' ')) for line in open(sys.argv[1])]
|
|
|
|
# challenge 1
|
|
scores = list(map(calc_score,games))
|
|
res1 = str(np.sum(scores))
|
|
print("challenge 1:" + "\n" + res1 + "\n")
|
|
|
|
# challenge 2
|
|
scores = list(map(calc_moves,games))
|
|
res2 = str(np.sum(scores))
|
|
print("challenge 2:" + "\n" + res2 + "\n")
|
|
|
|
|