diff --git a/2023/day-20/src/part1.rs b/2023/day-20/src/part1.rs index 2085549..696b86d 100644 --- a/2023/day-20/src/part1.rs +++ b/2023/day-20/src/part1.rs @@ -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() } diff --git a/2023/day-20/src/part2.rs b/2023/day-20/src/part2.rs index 1f5212d..4d4f17e 100644 --- a/2023/day-20/src/part2.rs +++ b/2023/day-20/src/part2.rs @@ -38,7 +38,7 @@ struct Module<'a> { } impl<'a> Module<'a> { - fn handle_pulse(&mut self, from: &'a str, pulse: Signal) -> Option{ + fn handle_pulse(&mut self, from: &'a str, pulse: Signal) -> Option { /*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)); diff --git a/2023/day-7/src/part1.rs b/2023/day-7/src/part1.rs index 3a24edb..9171589 100644 --- a/2023/day-7/src/part1.rs +++ b/2023/day-7/src/part1.rs @@ -86,11 +86,7 @@ impl From<&Hand> for HandType { acc.entry(card).and_modify(|c| *c += 1).or_insert(1); acc }); - match map - .into_values() - .sorted_by(|a, &b| b.cmp(a)) - .as_slice() - { + match map.into_values().sorted_by(|a, &b| b.cmp(a)).as_slice() { [5, ..] => Self::FiveOfAKind, [4, ..] => Self::FourOfAKind, [3, 2, ..] => Self::FullHouse, diff --git a/2023/day-7/src/part2.rs b/2023/day-7/src/part2.rs index a5debd6..1631439 100644 --- a/2023/day-7/src/part2.rs +++ b/2023/day-7/src/part2.rs @@ -101,16 +101,15 @@ enum HandType { impl From<&Hand> for HandType { fn from(value: &Hand) -> Self { - let mut map = value.cards.into_iter().fold(BTreeMap::new(), |mut acc, card| { - acc.entry(card).and_modify(|c| *c += 1).or_insert(1); - acc - }); + let mut map = value + .cards + .into_iter() + .fold(BTreeMap::new(), |mut acc, card| { + acc.entry(card).and_modify(|c| *c += 1).or_insert(1); + acc + }); let jokers = map.remove(&Card::Joker).unwrap_or(0); - match map - .into_values() - .sorted_by(|a, &b| b.cmp(a)) - .as_slice() - { + match map.into_values().sorted_by(|a, &b| b.cmp(a)).as_slice() { [x, ..] if jokers + x == 5 => Self::FiveOfAKind, [] if jokers == 5 => Self::FiveOfAKind, [x, ..] if jokers + x == 4 => Self::FourOfAKind,