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 Day 1 solution for 2016

+41
+40
2016/day01.py
··· 1 + import fileinput 2 + import sys 3 + 4 + DIRS = [ 5 + (1, 0), # north 6 + (0, 1), # east 7 + (-1, 0), # south 8 + (0, -1) # west 9 + ] 10 + 11 + seen = set() 12 + double_visit = False 13 + 14 + x = 0 15 + y = 0 16 + facing = 0 17 + 18 + for line in fileinput.input(): 19 + directions = line.split(', ') 20 + 21 + for d in directions: 22 + turn = d[0] 23 + steps = int(d[1:]) 24 + 25 + if turn == 'L': 26 + facing = (facing - 1) % 4 27 + else: 28 + facing = (facing + 1) % 4 29 + 30 + for _ in range(steps): 31 + x += DIRS[facing][0] 32 + y += DIRS[facing][1] 33 + 34 + if not double_visit and (x, y) in seen: 35 + print "First double-visit at ({}, {}) ({} blocks away)".format(x, y, abs(x) + abs(y)) 36 + double_visit = True 37 + else: 38 + seen.add((x, y)) 39 + 40 + print "Easter Bunny HQ is at ({}, {}) ({} blocks away)".format(x, y, abs(x) + abs(y))
+1
2016/input01.txt
··· 1 + R3, L5, R1, R2, L5, R2, R3, L2, L5, R5, L4, L3, R5, L1, R3, R4, R1, L3, R3, L2, L5, L2, R4, R5, R5, L4, L3, L3, R4, R4, R5, L5, L3, R2, R2, L3, L4, L5, R1, R3, L3, R2, L3, R5, L194, L2, L5, R2, R1, R1, L1, L5, L4, R4, R2, R2, L4, L1, R2, R53, R3, L5, R72, R2, L5, R3, L4, R187, L4, L5, L2, R1, R3, R5, L4, L4, R2, R5, L5, L4, L3, R5, L2, R1, R1, R4, L1, R2, L3, R5, L4, R2, L3, R1, L4, R4, L1, L2, R3, L1, L1, R4, R3, L4, R2, R5, L2, L3, L3, L1, R3, R5, R2, R3, R1, R2, L1, L4, L5, L2, R4, R5, L2, R4, R4, L3, R2, R1, L4, R3, L3, L4, L3, L1, R3, L2, R2, L4, L4, L5, R3, R5, R3, L2, R5, L2, L1, L5, L1, R2, R4, L5, R2, L4, L5, L4, L5, L2, L5, L4, R5, R3, R2, R2, L3, R3, L2, L5