diff --git a/aoc-solver/src/y2023/day20.rs b/aoc-solver/src/y2023/day20.rs index 7fb012e..aeea499 100644 --- a/aoc-solver/src/y2023/day20.rs +++ b/aoc-solver/src/y2023/day20.rs @@ -60,8 +60,6 @@ fn parse(input: &str) -> Result, AocError> { .try_collect()?; let mut inputs: HashMap> = HashMap::new(); - - // Construct module inputs for (name, module) in modules.iter() { for output in &module.outputs { inputs.entry(output.clone()).or_default().push(name.clone()); @@ -121,14 +119,14 @@ fn press_button( }; if let Some(output) = output { - emit_output( - output, - ¤t, - module, - &mut output_buffer, - &mut lows, - &mut highs, - ); + match output { + true => highs += module.outputs.len() as u32, + false => lows += module.outputs.len() as u32, + } + + for target in &module.outputs { + output_buffer.push_back((target.clone(), output, current.to_owned())); + } } } } @@ -136,24 +134,6 @@ fn press_button( (lows, highs) } -fn emit_output( - output: bool, - source: &str, - module: &mut Module, - output_buffer: &mut VecDeque<(String, bool, String)>, - lows: &mut u32, - highs: &mut u32, -) { - match output { - true => *highs += module.outputs.len() as u32, - false => *lows += module.outputs.len() as u32, - } - - for target in &module.outputs { - output_buffer.push_back((target.clone(), output, source.to_owned())); - } -} - fn gcd(a: u64, b: u64) -> u64 { if b == 0 { a