123456789101112131415161718192021222324252627282930313233343536373839 |
- #!/usr/bin/python3
- import sys
- # part 1
- # A/X rock, B/Y paper, C/Z scissors
- win = { 'A': 'Y', 'B': 'Z', 'C': 'X', }
- draw = { 'A': 'X', 'B': 'Y', 'C': 'Z', }
- loss = { 'A': 'Z', 'B': 'X', 'C': 'Y', }
- scores = { 'X': 1, 'Y': 2, "Z": 3, }
- def calculate_points(col1, col2):
- score = scores[col2] + 6 if win[col1] == col2 else \
- scores[col2] + 3 if draw[col1] == col2 else \
- scores[col2] + 0
- return score
- def part1():
- total = 0
- for line in sys.stdin:
- col1, col2 = line.strip().split(' ')
- total += calculate_points(col1, col2)
- print(f'total score of {total} points')
- # part 2
- mapping = { 'X': loss, 'Y': draw, 'Z': win }
- def part2():
- total = 0
- for line in sys.stdin:
- prediction, strategy = line.strip().split(' ')
- move = mapping[strategy][prediction]
- #print(prediction, strategy, move)
- total += calculate_points(prediction, move)
- print(f'total score of {total} points')
- if sys.argv[1] in '1':
- part1()
- else:
- part2()
|