Compare commits
3 Commits
78df584c4d
...
6a204e5f59
Author | SHA1 | Date | |
---|---|---|---|
6a204e5f59 | |||
00ae1c3f7d | |||
085a02b2d5 |
26
test.py
Normal file
26
test.py
Normal file
@ -0,0 +1,26 @@
|
||||
# JS sucks
|
||||
for line in open('./y2024/resources/17_input.txt'):
|
||||
if line.startswith('Program:'):
|
||||
instructions = list(map(int, line.split(': ')[1].split(',')))
|
||||
|
||||
def outFromA(a):
|
||||
interim = (a % 8) ^ 3
|
||||
c = a // (2 ** interim)
|
||||
postC = c ^ 6
|
||||
return (postC ^ (a % 8)) % 8
|
||||
|
||||
candidates = [0]
|
||||
for i in range(len(instructions) - 1, -1, -1):
|
||||
newCandidates = []
|
||||
# print(f'Instruction: {instructions[i]}, candidates: {candidates}')
|
||||
for c in candidates:
|
||||
for j in range(8):
|
||||
num = (c << 3) + j
|
||||
out = outFromA(num)
|
||||
# print(f'Num: {num}, Out: {out}, Instruction: {instructions[i]}')
|
||||
if out == instructions[i]:
|
||||
newCandidates.append(num)
|
||||
candidates = newCandidates
|
||||
|
||||
# print(candidates)
|
||||
print(min(candidates))
|
Loading…
Reference in New Issue
Block a user