@@ -93,29 +93,27 @@ fn run<'a>(
93
93
94
94
let mut queue = VecDeque :: from_iter ( gates) ;
95
95
96
- while !queue. is_empty ( ) {
97
- while let Some ( g) = queue. pop_front ( ) {
98
- let out = renames. get ( & g. out ) . unwrap_or ( & g. out ) ;
99
-
100
- // get values of a and b or push them back into the queue if
101
- // their values aren't available yet
102
- let Some ( & a) = wires. get ( g. a ) else {
103
- queue. push_back ( g) ;
104
- continue ;
105
- } ;
106
- let Some ( & b) = wires. get ( g. b ) else {
107
- queue. push_back ( g) ;
108
- continue ;
109
- } ;
96
+ while let Some ( g) = queue. pop_front ( ) {
97
+ let out = renames. get ( & g. out ) . unwrap_or ( & g. out ) ;
98
+
99
+ // get values of a and b or push them back into the queue if
100
+ // their values aren't available yet
101
+ let Some ( & a) = wires. get ( g. a ) else {
102
+ queue. push_back ( g) ;
103
+ continue ;
104
+ } ;
105
+ let Some ( & b) = wires. get ( g. b ) else {
106
+ queue. push_back ( g) ;
107
+ continue ;
108
+ } ;
110
109
111
- let v = match g. logic {
112
- Logic :: And => a && b,
113
- Logic :: Or => a || b,
114
- Logic :: Xor => a != b,
115
- } ;
110
+ let v = match g. logic {
111
+ Logic :: And => a && b,
112
+ Logic :: Or => a || b,
113
+ Logic :: Xor => a != b,
114
+ } ;
116
115
117
- wires. insert ( out, v) ;
118
- }
116
+ wires. insert ( out, v) ;
119
117
}
120
118
121
119
get_value ( & wires, "z" )
@@ -211,7 +209,7 @@ fn main() {
211
209
broken_nodes. sort ( ) ;
212
210
println ! ( "{}" , broken_nodes. join( "," ) ) ;
213
211
214
- // hard-coded answer for my puzzle input
212
+ // hard-coded answer for my puzzle input (just to check if the code above works)
215
213
let renames = HashMap :: from ( [
216
214
// 1
217
215
( "kqh" , "ddn" ) ,
@@ -233,7 +231,10 @@ fn main() {
233
231
if total2 == x + y {
234
232
let mut broken_nodes2 = renames. keys ( ) . copied ( ) . collect :: < Vec < _ > > ( ) ;
235
233
broken_nodes2. sort ( ) ;
236
- assert_eq ! ( broken_nodes, broken_nodes2) ;
234
+ assert_eq ! (
235
+ broken_nodes, broken_nodes2,
236
+ "This check is just for my puzzle input"
237
+ ) ;
237
238
} else {
238
239
panic ! ( "Unsolvable" ) ;
239
240
}
0 commit comments