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.

Add solution for 2018/09

+45
+42
2018/day09.py
··· 1 + import fileinput 2 + from utils import parse_nums 3 + 4 + 5 + class Node: 6 + def __init__(self, val, n=None, p=None): 7 + self.val = val 8 + self.next = n 9 + self.prev = p 10 + 11 + 12 + PLAYERS, MARBLES = parse_nums(fileinput.input()[0]) 13 + scores = [0] * PLAYERS 14 + player = 0 15 + 16 + curr = Node(0) 17 + curr.next = curr 18 + curr.prev = curr 19 + 20 + for 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 + 42 + print "Newer winning score:", max(scores)
+1
2018/inputs/09.txt
··· 1 + 418 players; last marble is worth 71339 points
+2
2018/outputs/09.txt
··· 1 + 412127 2 + 3482394794