From 3e7436200c6ba9ae2b4b6a8147520346e9f70736 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Thu, 21 Dec 2023 20:29:24 +0200 Subject: Day 20 part 2 - print some extra info that allowed figuring it out manually --- 2023/src/bin/day_20.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to '2023/src/bin/day_20.rs') diff --git a/2023/src/bin/day_20.rs b/2023/src/bin/day_20.rs index 070093a..f2e955f 100644 --- a/2023/src/bin/day_20.rs +++ b/2023/src/bin/day_20.rs @@ -32,14 +32,19 @@ fn main() -> Result<(), Box> { .find(|m| m.id == ModuleId::rx()) .unwrap() .index, + circuit + .modules + .iter() + .find(|m| m.id == ModuleId::from_short_alphanumeric("th").unwrap()) + .unwrap() + .index, ); - let mut i = 0; while !pulse_tracker.rx_got_a_low_pulse { + pulse_tracker.i += 1; circuit.push_the_button(&mut pulse_tracker); - i += 1; } - dbg!(i, pulse_tracker); + dbg!(pulse_tracker.i, pulse_tracker); } Ok(()) @@ -87,14 +92,18 @@ struct RxWatcher { pulses: VecDeque, rx_module_index: usize, rx_got_a_low_pulse: bool, + logging_module_index: usize, + i: usize, } impl RxWatcher { - fn new(rx_module_index: usize) -> Self { + fn new(rx_module_index: usize, logging_module_index: usize) -> Self { RxWatcher { pulses: VecDeque::default(), rx_module_index, rx_got_a_low_pulse: false, + logging_module_index, + i: 0, } } } @@ -266,6 +275,9 @@ impl PulseTracker for RxWatcher { fn button_pulse(&mut self) {} fn push(&mut self, pulse: Pulse) { + if pulse.state && pulse.output == self.logging_module_index { + println!("{}: {} into {}", self.i, pulse.input, pulse.output); + } if !pulse.state && pulse.output == self.rx_module_index { self.rx_got_a_low_pulse = true; } -- cgit v1.2.3