Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# pawlos/advent_of_code_d13_p1.py Secret

Last active Dec 27, 2017
Solution to Day 13: Packet Scanners - Part 1
 #aoc_d13.py inp = ["0: 3","1: 2","4: 4","6: 4"] inp = open('input_d13.txt','r').readlines() data = [d.split(':') for d in inp] dic = {} data = dict(data) maximum = int(max(data))+1 print maximum scanners = [None]*maximum direction = *maximum pos = *maximum print data for i in range(maximum): if str(i) in data: scanners[i] = [None]*int(data[str(i)]) direction[i] = 1 else: scanners[i] = [None] direction[i] = 0 for i in range(maximum): if scanners[i] != [None]: scanners[i] = 'S' caught = 0 for i in range(maximum): print scanners if scanners[i] == 'S': print 'have it' print len(scanners[i]),i caught += (i*len(scanners[i])) for k in range(len(pos)): scanners[k][pos[k]] = None pos[k] += direction[k] if pos[k] + direction[k] >= len(scanners[k]): direction[k] *= -1 elif pos[k] + direction[k] < 0: direction[k] *= -1 if scanners[k] != [None]: scanners[k][pos[k]] = 'S' print caught
to join this conversation on GitHub. Already have an account? Sign in to comment