Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solution to Day 19: A Series of Tubes - Part 1
#!/bin/python
#aoc_d19.py
inp = open("demo_d19.txt").readlines()
inp = open("input_d19.txt").readlines()
#inp = [c for c in inp]
l = 0
i = 0
print 'Z',ord(inp[l][i])
while inp[l][i] != '|':
i += 1
print 'S:',l,i
packet = ''
direction_y = 1
direction_x = 0
r = 0
while True:
l += direction_y
i += direction_x
#print l,i, inp[l][i]
if inp[l][i] == '|':
pass
#direction_y = 1
elif inp[l][i] == '-':
pass
elif inp[l][i] == '+':
if direction_y != 0:
#print 'p 1', inp[l][i+1], inp[l][i-1]
if inp[l][i+1] != ' ' :
#print 'i+1'
direction_x = 1
direction_y = 0
if inp[l][i-1] != ' ':
#print 'i-1'
direction_x = -1
direction_y = 0
elif direction_x != 0:
#print 'p 2'
if l < len(inp)-1 and inp[l+1][i] != ' ':
direction_x = 0
direction_y = 1
if l>0 and inp[l-1][i] != ' ':
direction_x = 0
direction_y = -1
#print 'Dir:', direction_y, direction_x
else:
packet += inp[l][i]
print packet
r += 1
if r > 105055:
break
print packet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment