@@ -21,49 +21,17 @@ fn part_a(input: &str) -> Answer {
21
21
}
22
22
23
23
fn part_b ( _input : & str ) -> Answer {
24
- // {
25
- // let mut processor = processor.clone();
26
- // *processor.reg_mut(0) = 1234;
27
-
28
- // while let Some(ins) = processor.next_instruction() {
29
- // ins.opcode.debug(&processor, ins.argument.clone());
30
- // ins.opcode.evaluate(&mut processor, ins.argument);
31
- // }
32
-
33
- // println!("{processor:?}");
34
- // }
35
-
36
- // while a != 0 {
37
- // b = a % 8;
38
- // b = b ^ 2;
39
- // c = a.wrapping_shr(b as u32);
40
- // b = b ^ c;
41
- // b = b ^ 3;
42
- // dbg!(b % 8);
43
- // a = a.wrapping_shr(3);
44
- // }
45
-
46
- // while a != 0 {
47
- // dbg!((((a % 8) ^ 2) ^ a.wrapping_shr((a % 8) as u32 ^ 2) ^ 3) % 8);
48
- // a = a.wrapping_shr(3);
49
- // }
24
+ // There is no way to make a general solution to this problem, so we have to
25
+ // rever engineer our specific input. In my case the input program
26
+ // translates into the following, where x is the input to the first
27
+ // register.
28
+ //
29
+ // (((x % 8) ^ 2) ^ x.wrapping_shr((x % 8) as u32 ^ 2) ^ 3) % 8
30
+ //
31
+ // Because an input can cause multiple outputs, we then use a recursive
32
+ // solver to create the needed input three bits at a time.
50
33
51
34
let exp = [ 2 , 4 , 1 , 2 , 7 , 5 , 4 , 7 , 1 , 3 , 5 , 5 , 0 , 3 , 3 , 0 ] ;
52
- // let mut out = 0;
53
-
54
- // for exp in [2, 4] {
55
- // for x in 0..=u64::MAX {
56
- // // let val = ((x ^ 2) ^ x.wrapping_shr(x as u32 ^ 2) ^ 3) % 8;
57
- // let val = (((x % 8) ^ 2) ^ x.wrapping_shr((x % 8) as u32 ^ 2) ^ 3) % 8;
58
- // println!("{x}: {val}");
59
- // if val == exp {
60
- // println!("{x}");
61
- // out <<= 3;
62
- // out |= x;
63
- // break;
64
- // }
65
- // }
66
- // }
67
35
68
36
fn solve ( exp : & [ u64 ] , n : usize , a : u64 ) -> u64 {
69
37
for inp in 0 ..=0b111u64 {
@@ -159,15 +127,6 @@ impl Processor {
159
127
}
160
128
}
161
129
162
- fn new ( program : Vec < u64 > ) -> Self {
163
- Self {
164
- registers : [ 0 , 0 , 0 ] ,
165
- program,
166
- ptr : 0 ,
167
- output : Vec :: new ( ) ,
168
- }
169
- }
170
-
171
130
fn reg ( & self , reg : u64 ) -> u64 {
172
131
self . registers [ reg as usize ]
173
132
}
@@ -222,6 +181,7 @@ impl OpCode {
222
181
}
223
182
}
224
183
184
+ #[ allow( unused) ]
225
185
fn debug ( & self , proc : & Processor , ( combo, literal) : ( Option < Argument > , u64 ) ) {
226
186
match self {
227
187
OpCode :: Adv => println ! ( "A = A >> {:?}" , combo. unwrap( ) ) ,
0 commit comments