2019 day 17 complete
This commit is contained in:
parent
ad53396ca6
commit
6cea472035
56
2019/d17.py
56
2019/d17.py
@ -51,9 +51,11 @@ def find_path(g):
|
|||||||
path += "R"
|
path += "R"
|
||||||
dir = DIRS[(DIRS.index(dir) + 1) % len(DIRS)]
|
dir = DIRS[(DIRS.index(dir) + 1) % len(DIRS)]
|
||||||
g[pos] = DIRCHAR[DIRS.index(dir)]
|
g[pos] = DIRCHAR[DIRS.index(dir)]
|
||||||
g.print()
|
|
||||||
input()
|
# For debugging:
|
||||||
print()
|
# g.print()
|
||||||
|
# input()
|
||||||
|
# print()
|
||||||
path = path.replace("RRR", "L")
|
path = path.replace("RRR", "L")
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@ -81,14 +83,48 @@ def part_1(data):
|
|||||||
# g[(r, c)] = 'o'
|
# g[(r, c)] = 'o'
|
||||||
result += r * c
|
result += r * c
|
||||||
print(result)
|
print(result)
|
||||||
g.print()
|
# g.print()
|
||||||
path = find_path(g)
|
|
||||||
print(path)
|
|
||||||
|
|
||||||
# xs = str_to_ints(data)
|
# Merge F commands into counts
|
||||||
# xs[0] = 2
|
path = find_path(g)
|
||||||
# a = Amp(xs)
|
path = list(path)
|
||||||
# a.go()
|
new_path = []
|
||||||
|
i = 0
|
||||||
|
while i < len(path):
|
||||||
|
if path[i] == "R":
|
||||||
|
new_path.append("R")
|
||||||
|
i += 1
|
||||||
|
elif path[i] == "L":
|
||||||
|
new_path.append("L")
|
||||||
|
i += 1
|
||||||
|
elif path[i] == "F":
|
||||||
|
count = 0
|
||||||
|
while i < len(path) and path[i] == "F":
|
||||||
|
count += 1
|
||||||
|
i += 1
|
||||||
|
new_path.append(str(count))
|
||||||
|
else:
|
||||||
|
assert False
|
||||||
|
path = new_path
|
||||||
|
print("Manually translate into commands:", "".join(path))
|
||||||
|
|
||||||
|
# manually created from above output
|
||||||
|
inst = (
|
||||||
|
"A,A,B,C,B,C,B,C,A,C\n"
|
||||||
|
"R,6,L,8,R,8\n"
|
||||||
|
"R,4,R,6,R,6,R,4,R,4\n"
|
||||||
|
"L,8,R,6,L,10,L,10\n"
|
||||||
|
"n\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
xs = str_to_ints(data)
|
||||||
|
xs[0] = 2
|
||||||
|
a = Amp(xs)
|
||||||
|
for c in inst:
|
||||||
|
a.feed(ord(c))
|
||||||
|
while not a.done:
|
||||||
|
a.go()
|
||||||
|
print(a.outputs[-1])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -128,7 +128,7 @@ Solutions and utility script for Advent of Code challenges in Python.
|
|||||||
- Day 14: >120:00 (Hmm, wasn't that hard either.)
|
- Day 14: >120:00 (Hmm, wasn't that hard either.)
|
||||||
- Day 15: >120:00 (I am really weak at the moment.)
|
- Day 15: >120:00 (I am really weak at the moment.)
|
||||||
- Day 16:
|
- Day 16:
|
||||||
- Day 17:
|
- Day 17: days (Fun but too tricky for me to be fast.)
|
||||||
- Day 18:
|
- Day 18:
|
||||||
- Day 19: 40:00 (Way too slow! Oversight error. Come on.)
|
- Day 19: 40:00 (Way too slow! Oversight error. Come on.)
|
||||||
- Day 20:
|
- Day 20:
|
||||||
|
Loading…
Reference in New Issue
Block a user