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 1.2 kB view raw
1import sys 2import fileinput 3 4from utils import memoize 5from intcode import emulate 6 7 8@memoize 9def affected(x, y): 10 if x < 0 or y < 0: 11 return 0 12 13 vm = emulate(TAPE, [y, x]) 14 return next(vm) 15 16 17# Read problem input 18TAPE = [int(x) for x in fileinput.input()[0].split(',')] 19 20 21part_1 = sum(affected(x, y) for y in range(50) for x in range(50)) 22print "Points affected by tractor beam:", part_1 23 24# Arbitrary starting point for my input that skips past the incontinuity 25x = 37 26y = 49 27 28while True: 29 while affected(x, y): 30 y += 1 31 32 assert affected(x, y) == 0 33 34 while not affected(x, y): 35 x += 1 36 37 while affected(x, y + 1): 38 y += 1 39 40 assert affected(x, y) == 1 41 assert affected(x + 1, y) == 1 42 assert affected(x - 1, y) == 0 43 assert affected(x, y + 1) == 0 44 assert affected(x, y - 1) == 1 45 46 if affected(x, y - 99) == 1 and affected(x + 99, y) == 1: 47 for yy in range(y - 99, y + 1): 48 for xx in range(x, x + 100): 49 if not affected(xx, yy): 50 break 51 else: 52 continue 53 54 break 55 else: 56 print "100x100 point checksum:", x * 10000 + (y - 99) 57 sys.exit()