Skip to content

Instantly share code, notes, and snippets.

@pawlos
Last active December 27, 2017 21:24
Show Gist options
  • Save pawlos/cb3578b4e29bb7ce753907a261b8256e to your computer and use it in GitHub Desktop.
Save pawlos/cb3578b4e29bb7ce753907a261b8256e to your computer and use it in GitHub Desktop.
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 = [1]*maximum
pos = [0]*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][0] = 'S'
caught = 0
for i in range(maximum):
print scanners
if scanners[i][0] == '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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment