y2024d17p2 test works
This commit is contained in:
parent
b410fa49ca
commit
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))
|
@ -63,17 +63,22 @@ pub fn process_part2(input: &str) -> u32 {
|
|||||||
.collect_vec()
|
.collect_vec()
|
||||||
.concat();
|
.concat();
|
||||||
let mut a = 0;
|
let mut a = 0;
|
||||||
loop {
|
for idx in 1..=orig.len() {
|
||||||
registers.insert("A", a);
|
let target = orig[orig.len() - idx..].to_vec();
|
||||||
let out = exec_program(instructions.clone(), &mut registers);
|
|
||||||
if out == orig {
|
|
||||||
println!("{orig:?}");
|
|
||||||
println!("{out:?}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
a += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let mut new_a = a << 3;
|
||||||
|
loop {
|
||||||
|
registers.insert("A", new_a);
|
||||||
|
let out = exec_program(instructions.clone(), &mut registers);
|
||||||
|
println!("target {target:?}");
|
||||||
|
println!("output {out:?}");
|
||||||
|
if out == target {
|
||||||
|
a = new_a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
new_a += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user