Something went wrong. Try again.
My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code
advent-of-code python
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243import fileinputfrom utils import parse_nums
class Node: def __init__(self, val, n=None, p=None): self.val = val self.next = n self.prev = p
PLAYERS, MARBLES = parse_nums(fileinput.input()[0])scores = [0] * PLAYERSplayer = 0
curr = Node(0)curr.next = currcurr.prev = curr
for m in range(1, MARBLES * 100): if m % 23 == 0: scores[player] += m for _ in range(7): curr = curr.prev
scores[player] += curr.val curr.prev.next = curr.next curr.next.prev = curr.prev curr = curr.prev.next else: curr = curr.next node = Node(m, p=curr, n=curr.next) curr.next.prev = node curr.next = node curr = node
player = (player + 1) % PLAYERS
if m == MARBLES: print "Winning elf's score:", max(scores)
print "Newer winning score:", max(scores)