summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-12-21 20:29:24 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-12-21 20:29:24 +0200
commit3e7436200c6ba9ae2b4b6a8147520346e9f70736 (patch)
treecd683e93c6b08eb9e3957d854dd3cab4e8ba4438
parentb15c097c3c5169dcaf36ef1951b4949041c9619a (diff)
Day 20 part 2 - print some extra info that allowed figuring it out manually
-rw-r--r--2023/src/bin/day_20.rs20
1 files changed, 16 insertions, 4 deletions
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<dyn std::error::Error>> {
.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<Pulse>,
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;
}