@@ -42,20 +42,18 @@ impl Puzzle {
4242 let opcode = self . program [ ip] ;
4343 let literal = self . program [ ip + 1 ] ;
4444
45- let combo = || {
46- return match literal {
47- 0 | 1 | 2 | 3 => literal,
48- 4 => a,
49- 5 => b,
50- 6 => c,
51- _ => panic ! ( ) ,
52- } ;
45+ let combo = || match literal {
46+ 0 ..=3 => literal,
47+ 4 => a,
48+ 5 => b,
49+ 6 => c,
50+ _ => panic ! ( ) ,
5351 } ;
5452
5553 match opcode {
5654 0 => {
5755 // adv
58- a = a >> literal;
56+ a >>= literal;
5957 }
6058 1 => {
6159 //bxl
@@ -120,7 +118,7 @@ impl Puzzle {
120118 1 => ( format ! ( "bxl {literal}" ) , format ! ( "b ^= {literal}" ) ) ,
121119 2 => ( format ! ( "bst {combo}" ) , format ! ( "b = {combo} % 8" ) ) ,
122120 3 => ( format ! ( "jnz {literal}" ) , format ! ( "jump {literal} if a≠0" ) ) ,
123- 4 => ( format ! ( "bxc" ) , format ! ( "b ^= c" ) ) ,
121+ 4 => ( "bxc" . to_string ( ) , "b ^= c" . to_string ( ) ) ,
124122 5 => ( format ! ( "out {combo}" ) , format ! ( "out {combo} % 8" ) ) ,
125123 6 => ( format ! ( "bdv {combo}" ) , format ! ( "b = a >> {combo}" ) ) ,
126124 7 => ( format ! ( "cdv {combo}" ) , format ! ( "c = a >> {combo}" ) ) ,
@@ -137,7 +135,7 @@ impl Puzzle {
137135
138136 output
139137 . iter ( )
140- . map ( |x| x . to_string ( ) )
138+ . map ( std :: string :: ToString :: to_string)
141139 . collect :: < Vec < String > > ( )
142140 . join ( "," )
143141 }
@@ -153,9 +151,9 @@ impl Puzzle {
153151 // jump 0 if a≠0
154152
155153 fn quine ( & self , a : u64 , i : usize , xor1 : u64 , xor2 : u64 ) -> u64 {
156- let target = self . program [ i] as u64 ;
154+ let target = u64 :: from ( self . program [ i] ) ;
157155
158- let start_octal = if i == self . program . len ( ) - 1 { 1 } else { 0 } ;
156+ let start_octal = u64 :: from ( i == self . program . len ( ) - 1 ) ;
159157
160158 for octal in start_octal..8 {
161159 let new_a = ( a * 8 ) | octal;
@@ -189,10 +187,10 @@ impl Puzzle {
189187 return 0 ;
190188 }
191189
192- let xor1 = xors[ 0 ] as u64 ;
193- let xor2 = xors[ 1 ] as u64 ;
190+ let xor_1 = u64 :: from ( xors[ 0 ] ) ;
191+ let xor_2 = u64 :: from ( xors[ 1 ] ) ;
194192
195- return self . quine ( 0 , self . program . len ( ) - 1 , xor1 , xor2 ) ;
193+ self . quine ( 0 , self . program . len ( ) - 1 , xor_1 , xor_2 )
196194 }
197195}
198196
0 commit comments