-
-
Save pawlos/32277a094a960761fba2c147ed9aa6dd to your computer and use it in GitHub Desktop.
Solution to Day 19: A Series of Tubes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 = 1 | |
while True: | |
r += 1 | |
if r % 100 == 0: | |
print r | |
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] == '+': | |
print '+', r | |
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: | |
if inp[l][i] == ' ': | |
break | |
packet += inp[l][i] | |
print packet,len(packet), r, l, i | |
if r > 52055: | |
break | |
print packet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment