reformatting

This commit is contained in:
Dylan Thies
2024-01-06 11:46:37 -05:00
parent 27613db8f7
commit 26262dcdb7
4 changed files with 14 additions and 23 deletions

View File

@@ -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()
}

View File

@@ -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() {

View File

@@ -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,

View File

@@ -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| {
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,