reformatting
This commit is contained in:
@@ -72,9 +72,7 @@ impl<'a> Module<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn push_button<'a>(
|
||||
setup: &mut BTreeMap<&'a str, Module<'a>>,
|
||||
) -> (usize, usize) {
|
||||
fn push_button<'a>(setup: &mut BTreeMap<&'a str, Module<'a>>) -> (usize, usize) {
|
||||
let mut queue = VecDeque::from(vec![("broadcaster", None, false)]);
|
||||
let mut low_signals = 1;
|
||||
let mut high_signals = 0;
|
||||
@@ -134,7 +132,7 @@ pub fn part1(input: &str) -> String {
|
||||
let (low, high) = push_button(&mut setup);
|
||||
high_count += high;
|
||||
low_count += low;
|
||||
};
|
||||
}
|
||||
|
||||
(high_count * low_count).to_string()
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ struct Module<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Module<'a> {
|
||||
fn handle_pulse(&mut self, from: &'a str, pulse: Signal) -> Option<Signal>{
|
||||
fn handle_pulse(&mut self, from: &'a str, pulse: Signal) -> Option<Signal> {
|
||||
/*println!(
|
||||
"{from} -{}-> {}",
|
||||
if pulse == Signal::Low { "low" } else { "high" },
|
||||
@@ -103,9 +103,7 @@ impl<'a> Module<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn push_button<'a>(
|
||||
setup: &mut BTreeMap<&'a str, Module<'a>>,
|
||||
) -> (bool, Vec<(&'a str, Signal)>) {
|
||||
fn push_button<'a>(setup: &mut BTreeMap<&'a str, Module<'a>>) -> (bool, Vec<(&'a str, Signal)>) {
|
||||
let mut queue = VecDeque::from(vec![("broadcaster", "button", Signal::Low)]);
|
||||
let mut triggered = Vec::new();
|
||||
while let Some((current_label, from, signal)) = queue.pop_front() {
|
||||
@@ -117,7 +115,7 @@ fn push_button<'a>(
|
||||
continue;
|
||||
};
|
||||
|
||||
if let Some(signal_to_send) = current.handle_pulse(from, signal){
|
||||
if let Some(signal_to_send) = current.handle_pulse(from, signal) {
|
||||
triggered.push((current_label, signal));
|
||||
current.connections.iter().for_each(|con| {
|
||||
queue.push_back((con, current_label, signal_to_send));
|
||||
|
||||
Reference in New Issue
Block a user