Finish 2019.

This commit is contained in:
felixm 2024-10-13 10:38:21 -04:00
parent 5dc7c4392f
commit 800d1a6af3
2 changed files with 161 additions and 1 deletions

160
2019/d25.py Normal file
View File

@ -0,0 +1,160 @@
from lib import get_data, ints
from d9 import Amp
from itertools import combinations
data = get_data(__file__)
xs = ints(data)
commands = [
"north",
"take candy cane",
"west",
"south",
"south",
"take fuel cell",
"south",
"take manifold",
"north",
"north",
"west",
"take mutex",
"north",
"south",
"south",
"south",
"take coin",
"south",
"north",
"east",
"take cake",
"west",
"east",
"north",
"south",
"west",
"east",
"east",
"north",
"south",
"west",
"north",
"west",
"east",
"west",
"south",
"west",
"north",
"north",
"south",
"west",
"north",
"east",
"south",
"west",
"east",
"west",
"south",
"west",
"take dehydrated water",
"west",
"east",
"west",
"south",
"take prime number",
"south",
"north",
"east",
"east",
"west",
"north",
"east",
"east",
"north",
"south",
"west",
"north",
"west",
"south",
"inv",
"west",
]
items = [
"cake",
"prime number",
"mutex",
"dehydrated water",
"coin",
"manifold",
"candy cane",
"fuel cell",
]
def run_command(a, s):
for c in s:
a.feed(ord(c))
a.feed(10)
a.go()
a = Amp(xs)
for c in commands:
a.go()
while a.outputs:
a.go()
a.pop()
# print(chr(a.pop()), end="")
run_command(a, c)
a.go()
def try_all(a):
subsets = [list(combinations(items, r)) for r in range(1, len(items) + 1)]
subsets = [item for sublist in subsets for item in sublist]
for subset in subsets:
for item in items:
c = f"drop {item}"
run_command(a, c)
a.go()
while a.outputs:
a.pop()
a.go()
for item in subset:
c = f"take {item}"
run_command(a, c)
a.go()
while a.outputs:
a.pop()
a.go()
run_command(a, "west")
output_str = ""
while a.outputs:
a.go()
output_str += chr(a.pop())
if "lighter" in output_str:
pass
elif "heavier" in output_str:
pass
else:
(password,) = ints(output_str)
print(password)
exit()
while True:
a.go()
output_str = ""
while a.outputs:
a.go()
output_str += chr(a.pop())
try_all(a)
if a.input_required:
c = input(">")
run_command(a, c)

View File

@ -140,7 +140,7 @@ Solutions and utility script for Advent of Code challenges in Python.
- Day 22: days (Needed some help...) - Day 22: days (Needed some help...)
- Day 23: 23:13 (Still too slow even though my int computer was in good shape...) - Day 23: 23:13 (Still too slow even though my int computer was in good shape...)
- Day 24: 53:00 (Can I ever even get points at all?) - Day 24: 53:00 (Can I ever even get points at all?)
- Day 25: - Day 25: 70:00 (Well, done at least. Super super fun!)
## AoC 2020 ## AoC 2020