Solve 2021 day 24
This commit is contained in:
88
2021/d24.py
88
2021/d24.py
@@ -2,62 +2,44 @@ from lib import get_data
|
|||||||
|
|
||||||
data = get_data(__file__)
|
data = get_data(__file__)
|
||||||
|
|
||||||
# lines = data.splitlines()
|
|
||||||
# blocks = [lines[i:i + 18] for i in range(0, len(lines), 18)]
|
|
||||||
# blocks = zip(*blocks)
|
|
||||||
# for row in blocks:
|
|
||||||
# print("; ".join(set(row)))
|
|
||||||
|
|
||||||
def run(number=None):
|
def run(number):
|
||||||
inputs = []
|
inputs = list(map(int, str(number)))
|
||||||
if number is not None:
|
assert len(inputs) == 14
|
||||||
for c in str(number):
|
|
||||||
if c == "0":
|
w, x, z = 0, 0, 0
|
||||||
return
|
i = 0
|
||||||
inputs.append(int(c))
|
for i in range(len(inputs)):
|
||||||
inputs = list(reversed(inputs))
|
w = inputs[i]
|
||||||
|
# print(f"{w=:3} {x=:3} {z=}")
|
||||||
|
|
||||||
|
to_add_x = [15, 15, 12, 13, -12, 10, -9, 14, 13, -14, -11, -2, -16, -14][i]
|
||||||
|
to_div_z = [1, 1, 1, 1, 26, 1, 26, 1, 1, 26, 26, 26, 26, 26][i]
|
||||||
|
to_add_z = [15, 10, 2, 16, 12, 11, 5, 16, 6, 15, 3, 12, 10, 13][i]
|
||||||
|
|
||||||
|
zz = z
|
||||||
|
x = (z % 26) + to_add_x
|
||||||
|
z = z // to_div_z
|
||||||
|
|
||||||
|
# print(f"{zz % 26=} + {to_add_x=} {x=}")
|
||||||
|
|
||||||
|
if x == w:
|
||||||
|
# print(f"added = 0")
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
inputs = None
|
z *= 26
|
||||||
|
z += w + to_add_z
|
||||||
|
# print(f"added {w=} + {to_add_z=} = {w + to_add_z}")
|
||||||
|
# print()
|
||||||
|
|
||||||
regs = {c: 0 for c in "wxyz"}
|
# print(f"\nEND:\n{w=} {x=} {z=}", "\n" * 15)
|
||||||
for i, line in enumerate(data.splitlines()):
|
return z
|
||||||
if line.startswith("inp"):
|
|
||||||
if inputs is not None:
|
|
||||||
if inputs == []:
|
|
||||||
print(number, regs)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
op, a = line.split()
|
|
||||||
regs[a] = inputs.pop()
|
|
||||||
else:
|
|
||||||
# print(regs)
|
|
||||||
op, a = line.split()
|
|
||||||
regs[a] = int(input(f"{i // 14} > "))
|
|
||||||
continue
|
|
||||||
|
|
||||||
op, a, b = line.split()
|
|
||||||
b = regs[b] if b in regs else int(b)
|
|
||||||
match op:
|
|
||||||
case "add":
|
|
||||||
regs[a] = regs[a] + b
|
|
||||||
case "mul":
|
|
||||||
regs[a] = regs[a] * b
|
|
||||||
case "div":
|
|
||||||
regs[a] = regs[a] // b
|
|
||||||
case "mod":
|
|
||||||
regs[a] = regs[a] % b
|
|
||||||
case "eql":
|
|
||||||
regs[a] = 1 if regs[a] == b else 0
|
|
||||||
|
|
||||||
|
|
||||||
print("end", inputs, number, regs)
|
largest_model_nr = 89959794919939
|
||||||
|
assert run(largest_model_nr) == 0
|
||||||
|
print(largest_model_nr)
|
||||||
|
|
||||||
|
lowest_model_nr = 17115131916112
|
||||||
run(19111111111111)
|
assert run(lowest_model_nr) == 0
|
||||||
|
print(lowest_model_nr)
|
||||||
# while True:
|
|
||||||
# try:
|
|
||||||
# run()
|
|
||||||
# except KeyboardInterrupt:
|
|
||||||
# print("\n restart <")
|
|
||||||
# pass
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ Solutions and utility script for Advent of Code challenges in Python.
|
|||||||
- Day 21: 37:45 (Wasn't hard but I was just too slow.)
|
- Day 21: 37:45 (Wasn't hard but I was just too slow.)
|
||||||
- Day 22:
|
- Day 22:
|
||||||
- Day 23: 81:38 (Fun but obviously not competitive.)
|
- Day 23: 81:38 (Fun but obviously not competitive.)
|
||||||
- Day 24:
|
- Day 24: 232:00 (Super hard for me but I am proud of it.)
|
||||||
- Day 25: 15:43 (That could have been much much faster.)
|
- Day 25: 15:43 (That could have been much much faster.)
|
||||||
|
|
||||||
## AoC 2022
|
## AoC 2022
|
||||||
|
|||||||
Reference in New Issue
Block a user