generated from public/aoc_template
day17 - another day, another failure
This commit is contained in:
parent
51666c7857
commit
c4066aaac6
63
day17.py
63
day17.py
@ -87,14 +87,14 @@ class Computer:
|
|||||||
|
|
||||||
def out(self, operand: int) -> None:
|
def out(self, operand: int) -> None:
|
||||||
value = self.get_combo_value(operand) % 8
|
value = self.get_combo_value(operand) % 8
|
||||||
self.output.append(value)
|
|
||||||
if not self.check_output:
|
if not self.check_output:
|
||||||
self.instr_pointer += 1
|
self.instr_pointer += 1
|
||||||
elif value != self.__code[len(self.output) - 1]:
|
self.output.append(value)
|
||||||
# print(f"Want to add {value} to {self.output=}, but expected {self.__code[len(self.output) - 1]}")
|
elif value != self.__code[len(self.output)]:
|
||||||
self.instr_pointer = len(self.code)
|
self.instr_pointer = len(self.code)
|
||||||
else:
|
else:
|
||||||
self.instr_pointer += 1
|
self.instr_pointer += 1
|
||||||
|
self.output.append(value)
|
||||||
|
|
||||||
def bdv(self, operand: int) -> None:
|
def bdv(self, operand: int) -> None:
|
||||||
self.reg_b = self.reg_a // (2 ** self.get_combo_value(operand))
|
self.reg_b = self.reg_a // (2 ** self.get_combo_value(operand))
|
||||||
@ -124,6 +124,7 @@ class Day(AOCDay):
|
|||||||
[
|
[
|
||||||
(117440, "input17_test2"),
|
(117440, "input17_test2"),
|
||||||
(202356708354602, "input17_neil"),
|
(202356708354602, "input17_neil"),
|
||||||
|
(236555995274861, "input17_dennis"),
|
||||||
(None, "input17"),
|
(None, "input17"),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
@ -142,46 +143,54 @@ class Day(AOCDay):
|
|||||||
expected_output = ",".join(str(x) for x in prog)
|
expected_output = ",".join(str(x) for x in prog)
|
||||||
computer = Computer(a, b, c, prog)
|
computer = Computer(a, b, c, prog)
|
||||||
computer.check_output = True
|
computer.check_output = True
|
||||||
print(computer.code)
|
|
||||||
|
def run_computer(v: int) -> str:
|
||||||
|
computer.reset()
|
||||||
|
computer.reg_a = v
|
||||||
|
computer.run_code()
|
||||||
|
return computer.get_output()
|
||||||
|
|
||||||
init_a = 0
|
init_a = 0
|
||||||
|
init_reg = 0
|
||||||
output = ""
|
output = ""
|
||||||
|
bit_match = ""
|
||||||
|
bit_width = 6
|
||||||
|
bit_add = bit_width - 1
|
||||||
factor = 0
|
factor = 0
|
||||||
additive = 0
|
additive = 0
|
||||||
|
best = 0
|
||||||
while output != expected_output:
|
while output != expected_output:
|
||||||
computer.reset()
|
|
||||||
init_reg = init_a * (8**factor) + additive
|
init_reg = init_a * (8**factor) + additive
|
||||||
if init_reg > 8 ** 16:
|
output = run_computer(init_reg)
|
||||||
print("FAIL! AGAIN!")
|
|
||||||
break
|
|
||||||
computer.reg_a = init_reg
|
|
||||||
computer.run_code()
|
|
||||||
output = computer.get_output()
|
|
||||||
if len(output) > factor + 1 and output == expected_output[:len(output)]:
|
|
||||||
print(init_a, init_reg, output, expected_output)
|
|
||||||
additive = (int(bin(init_reg)[-6:], 2) << (3 * factor)) | additive
|
|
||||||
#additive += int(bin(init_reg)[-6:], 2)
|
|
||||||
factor += 2
|
|
||||||
|
|
||||||
if len(output) > 3 and output == expected_output[:len(output)]:
|
if len(output) > best and output == expected_output[: len(output)]:
|
||||||
print(f"{init_a=}, {factor=}, {additive=}, {output=}, {expected_output=}")
|
# if output == expected_output[: len(output)]:
|
||||||
|
o = oct(init_reg)
|
||||||
|
if o[-bit_width:] != bit_match:
|
||||||
|
bit_match = o[-bit_width:]
|
||||||
|
else:
|
||||||
|
additive = int(bit_match, 8)
|
||||||
|
factor = bit_width
|
||||||
|
bit_width += bit_add
|
||||||
|
bit_add -= 1
|
||||||
|
init_a = 0
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"{init_reg=} ({oct(init_reg)}), {factor=}, additive={oct(additive)}, {output=}, {expected_output=}"
|
||||||
|
)
|
||||||
|
best = len(output)
|
||||||
|
|
||||||
if init_a % 1_000_000 == 0:
|
if init_a % 1_000_000 == 0:
|
||||||
print(init_a, init_reg)
|
print(init_a, init_reg)
|
||||||
init_a += 1
|
init_a += 1
|
||||||
|
|
||||||
print(init_a - 1, (init_a - 1) * (8**factor) + additive)
|
print(init_a - 1, (init_a - 1) * (8**factor) + additive)
|
||||||
computer.reset()
|
output = run_computer(init_reg)
|
||||||
computer.reg_a = init_a - 1
|
print(output)
|
||||||
computer.run_code()
|
if output == expected_output:
|
||||||
print(computer.get_output())
|
return init_reg
|
||||||
if computer.get_output() == expected_output:
|
|
||||||
return init_a - 1
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
first = []
|
first = []
|
||||||
for i, c in enumerate(prog):
|
for i, c in enumerate(prog):
|
||||||
reg_a_init = 0
|
reg_a_init = 0
|
||||||
|
|||||||
5
inputs/input17_dennis
Normal file
5
inputs/input17_dennis
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Register A: 30118712
|
||||||
|
Register B: 0
|
||||||
|
Register C: 0
|
||||||
|
|
||||||
|
Program: 2,4,1,3,7,5,4,2,0,3,1,5,5,5,3,0
|
||||||
Loading…
Reference in New Issue
Block a user