summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-12-21 09:49:23 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-12-21 09:49:23 +0200
commitb15c097c3c5169dcaf36ef1951b4949041c9619a (patch)
tree7667465645ee8d591c469fe04b84fe855d9f86fb
parentde87554bf2ddb5716806608705b549e0732f431d (diff)
Day 20, Fix up connecting the rx fake module
-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 0829365..070093a 100644
--- a/2023/src/bin/day_20.rs
+++ b/2023/src/bin/day_20.rs
@@ -13,7 +13,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let input = fs::read_to_string("inputs/day_20.txt")?;
let circuit = Circuit::parser(&input).unwrap().1;
- dbg!(&circuit);
{
let mut circuit = circuit.clone();
let mut pulse_tracker = PulseCounter::default();
@@ -30,7 +29,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
circuit
.modules
.iter()
- .find(|m| m.id == ModuleId::from_short_alphanumeric("rx").unwrap())
+ .find(|m| m.id == ModuleId::rx())
.unwrap()
.index,
);
@@ -135,7 +134,16 @@ impl Circuit {
.iter()
.enumerate()
.find(|(_, out)| &out.id == out_id)
- .map_or(sink_index, |(index, _)| index + 1)
+ .map_or_else(
+ || {
+ if out_id == &ModuleId::rx() {
+ rx_sink_index
+ } else {
+ sink_index
+ }
+ },
+ |(index, _)| index + 1,
+ )
})
.collect(),
state: module.state.clone(),
@@ -148,7 +156,7 @@ impl Circuit {
state: ModuleState::Sink,
});
modules.push(Module {
- id: ModuleId::from_short_alphanumeric("rx").unwrap(),
+ id: ModuleId::rx(),
index: rx_sink_index,
outs: Vec::new(),
state: ModuleState::Sink,
@@ -304,6 +312,10 @@ impl ModuleId {
ModuleId(u32::MAX)
}
+ fn rx() -> ModuleId {
+ ModuleId::from_short_alphanumeric("rx").unwrap()
+ }
+
fn from_short_alphanumeric(s: &str) -> Result<ModuleId, ParseIntError> {
u32::from_str_radix(s, 36).map(ModuleId)
}