My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 57 lines 825 B view raw
1import fileinput 2 3wins = { 4 'A': 'Y', 5 'B': 'Z', 6 'C': 'X', 7} 8 9losses = { 10 'B': 'X', 11 'C': 'Y', 12 'A': 'Z', 13} 14 15draw = { 16 'A': 'X', 17 'B': 'Y', 18 'C': 'Z', 19} 20 21score = { 22 'X': 1, 23 'Y': 2, 24 'Z': 3, 25} 26 27INPUT = [line.strip() for line in fileinput.input()] 28 29part_1 = 0 30for line in INPUT: 31 op, us = line.split(' ') 32 33 part_1 += score[us] 34 if wins[op] == us: 35 part_1 += 6 36 elif losses[op] == us: 37 part_1 += 0 38 else: 39 part_1 += 3 40 41print("Part 1:", part_1) 42 43part_2 = 0 44for line in INPUT: 45 op, outcome = line.split(' ') 46 if outcome == 'X': 47 us = losses[op] 48 part_2 += score[us] 49 elif outcome == 'Y': 50 us = draw[op] 51 part_2 += score[us] + 3 52 else: 53 us = wins[op] 54 part_2 += score[us] + 6 55 56print("Part 2:", part_2) 57