generated from public/aoc_template
day17 - :(
This commit is contained in:
parent
35f2a3e4ae
commit
fc7c1fe939
99
day17.py
99
day17.py
@ -1,3 +1,4 @@
|
|||||||
|
import math
|
||||||
import sys
|
import sys
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from tools.aoc import AOCDay
|
from tools.aoc import AOCDay
|
||||||
@ -117,10 +118,12 @@ class Day(AOCDay):
|
|||||||
inputs = [
|
inputs = [
|
||||||
[
|
[
|
||||||
("4,6,3,5,6,3,5,2,1,0", "input17_test"),
|
("4,6,3,5,6,3,5,2,1,0", "input17_test"),
|
||||||
|
("7,1,2,3,2,6,7,2,5", "input17_neil"),
|
||||||
("1,6,3,6,5,6,5,1,7", "input17"),
|
("1,6,3,6,5,6,5,1,7", "input17"),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
# (117440, "input17_test2"),
|
(117440, "input17_test2"),
|
||||||
|
(202356708354602, "input17_neil"),
|
||||||
(None, "input17"),
|
(None, "input17"),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
@ -138,24 +141,96 @@ class Day(AOCDay):
|
|||||||
a, b, c, prog = self.parse_input()
|
a, b, c, prog = self.parse_input()
|
||||||
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)
|
||||||
print(computer.code)
|
|
||||||
computer.check_output = True
|
computer.check_output = True
|
||||||
reg_a_init = 0
|
print(computer.code)
|
||||||
ex_len = 1
|
|
||||||
|
init_a = 0
|
||||||
output = ""
|
output = ""
|
||||||
|
factor = 0
|
||||||
|
additive = 0
|
||||||
while output != expected_output:
|
while output != expected_output:
|
||||||
reg_a_init += 1
|
|
||||||
computer.reset()
|
computer.reset()
|
||||||
computer.reg_a = reg_a_init
|
init_reg = init_a * (8 ** factor) + additive
|
||||||
|
if init_reg > 8 ** 16:
|
||||||
|
print("FAIL! AGAIN!")
|
||||||
|
break
|
||||||
|
computer.reg_a = init_reg
|
||||||
computer.run_code()
|
computer.run_code()
|
||||||
output = computer.get_output()
|
output = computer.get_output()
|
||||||
if output.startswith(expected_output[:ex_len]):
|
if len(output) > factor + 1 and output == expected_output[:len(output)]:
|
||||||
print(f"Computer Reg A: {reg_a_init}, BXL: {reg_a_init ^ 1}")
|
print(init_a, init_reg, output, expected_output)
|
||||||
print(f"Computer Output: {output}")
|
additive = (int(bin(init_reg)[-6:], 2) << (3 * factor)) | additive
|
||||||
sys.stdout.flush()
|
#additive += int(bin(init_reg)[-6:], 2)
|
||||||
ex_len += 2
|
factor += 2
|
||||||
|
|
||||||
return reg_a_init
|
if len(output) > 3 and output == expected_output[:len(output)]:
|
||||||
|
print(f"{init_a=}, {factor=}, {additive=}, {output=}, {expected_output=}")
|
||||||
|
|
||||||
|
if init_a % 1_000_000 == 0:
|
||||||
|
print(init_a, init_reg)
|
||||||
|
init_a += 1
|
||||||
|
|
||||||
|
print(init_a - 1, (init_a - 1) * (8 ** factor) + additive)
|
||||||
|
computer.reset()
|
||||||
|
computer.reg_a = init_a - 1
|
||||||
|
computer.run_code()
|
||||||
|
print(computer.get_output())
|
||||||
|
if computer.get_output() == expected_output:
|
||||||
|
return init_a - 1
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
first = []
|
||||||
|
for i, c in enumerate(prog):
|
||||||
|
reg_a_init = 0
|
||||||
|
|
||||||
|
while len(first) <= i:
|
||||||
|
computer.reset()
|
||||||
|
computer.reg_a = reg_a_init
|
||||||
|
computer.run_code()
|
||||||
|
if int(computer.get_output()[0]) == c:
|
||||||
|
first.append(reg_a_init)
|
||||||
|
|
||||||
|
reg_a_init += 1
|
||||||
|
|
||||||
|
print(first)
|
||||||
|
result = 0
|
||||||
|
for i, c in enumerate(reversed(first)):
|
||||||
|
result = result << 3
|
||||||
|
result += c // 8
|
||||||
|
#result = sum(((x * (8 ** i) for i, x in enumerate(first))))
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
computer.reset()
|
||||||
|
computer.reg_a = result
|
||||||
|
computer.run_code()
|
||||||
|
print(computer.get_output())
|
||||||
|
if computer.get_output() == expected_output:
|
||||||
|
return result
|
||||||
|
|
||||||
|
while computer.get_output() != expected_output:
|
||||||
|
result -= 1
|
||||||
|
computer.reset()
|
||||||
|
computer.reg_a = result
|
||||||
|
computer.run_code()
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
for i in range(len(first)):
|
||||||
|
result = sum(((x * (8 ** i) for i, x in enumerate(first[:i + 1]))))
|
||||||
|
print("Testing ", first[:i + 1], "=", result)
|
||||||
|
computer.reset()
|
||||||
|
computer.reg_a = result
|
||||||
|
computer.run_code()
|
||||||
|
print(expected_output)
|
||||||
|
print(computer.get_output())
|
||||||
|
|
||||||
|
if computer.get_output() == expected_output:
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
5
inputs/input17_neil
Normal file
5
inputs/input17_neil
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Register A: 32916674
|
||||||
|
Register B: 0
|
||||||
|
Register C: 0
|
||||||
|
|
||||||
|
Program: 2,4,1,1,7,5,0,3,1,4,4,0,5,5,3,0
|
||||||
Loading…
Reference in New Issue
Block a user