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 42 lines 891 B view raw
1import fileinput 2from utils import parse_nums 3 4 5class Node: 6 def __init__(self, val, n=None, p=None): 7 self.val = val 8 self.next = n 9 self.prev = p 10 11 12PLAYERS, MARBLES = parse_nums(fileinput.input()[0]) 13scores = [0] * PLAYERS 14player = 0 15 16curr = Node(0) 17curr.next = curr 18curr.prev = curr 19 20for m in range(1, MARBLES * 100): 21 if m % 23 == 0: 22 scores[player] += m 23 for _ in range(7): 24 curr = curr.prev 25 26 scores[player] += curr.val 27 curr.prev.next = curr.next 28 curr.next.prev = curr.prev 29 curr = curr.prev.next 30 else: 31 curr = curr.next 32 node = Node(m, p=curr, n=curr.next) 33 curr.next.prev = node 34 curr.next = node 35 curr = node 36 37 player = (player + 1) % PLAYERS 38 39 if m == MARBLES: 40 print "Winning elf's score:", max(scores) 41 42print "Newer winning score:", max(scores)