reformatting
This commit is contained in:
@@ -72,9 +72,7 @@ impl<'a> Module<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_button<'a>(
|
fn push_button<'a>(setup: &mut BTreeMap<&'a str, Module<'a>>) -> (usize, usize) {
|
||||||
setup: &mut BTreeMap<&'a str, Module<'a>>,
|
|
||||||
) -> (usize, usize) {
|
|
||||||
let mut queue = VecDeque::from(vec![("broadcaster", None, false)]);
|
let mut queue = VecDeque::from(vec![("broadcaster", None, false)]);
|
||||||
let mut low_signals = 1;
|
let mut low_signals = 1;
|
||||||
let mut high_signals = 0;
|
let mut high_signals = 0;
|
||||||
@@ -134,7 +132,7 @@ pub fn part1(input: &str) -> String {
|
|||||||
let (low, high) = push_button(&mut setup);
|
let (low, high) = push_button(&mut setup);
|
||||||
high_count += high;
|
high_count += high;
|
||||||
low_count += low;
|
low_count += low;
|
||||||
};
|
}
|
||||||
|
|
||||||
(high_count * low_count).to_string()
|
(high_count * low_count).to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ struct Module<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> 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!(
|
/*println!(
|
||||||
"{from} -{}-> {}",
|
"{from} -{}-> {}",
|
||||||
if pulse == Signal::Low { "low" } else { "high" },
|
if pulse == Signal::Low { "low" } else { "high" },
|
||||||
@@ -103,9 +103,7 @@ impl<'a> Module<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_button<'a>(
|
fn push_button<'a>(setup: &mut BTreeMap<&'a str, Module<'a>>) -> (bool, Vec<(&'a str, Signal)>) {
|
||||||
setup: &mut BTreeMap<&'a str, Module<'a>>,
|
|
||||||
) -> (bool, Vec<(&'a str, Signal)>) {
|
|
||||||
let mut queue = VecDeque::from(vec![("broadcaster", "button", Signal::Low)]);
|
let mut queue = VecDeque::from(vec![("broadcaster", "button", Signal::Low)]);
|
||||||
let mut triggered = Vec::new();
|
let mut triggered = Vec::new();
|
||||||
while let Some((current_label, from, signal)) = queue.pop_front() {
|
while let Some((current_label, from, signal)) = queue.pop_front() {
|
||||||
@@ -117,7 +115,7 @@ fn push_button<'a>(
|
|||||||
continue;
|
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));
|
triggered.push((current_label, signal));
|
||||||
current.connections.iter().for_each(|con| {
|
current.connections.iter().for_each(|con| {
|
||||||
queue.push_back((con, current_label, signal_to_send));
|
queue.push_back((con, current_label, signal_to_send));
|
||||||
|
|||||||
@@ -86,11 +86,7 @@ impl From<&Hand> for HandType {
|
|||||||
acc.entry(card).and_modify(|c| *c += 1).or_insert(1);
|
acc.entry(card).and_modify(|c| *c += 1).or_insert(1);
|
||||||
acc
|
acc
|
||||||
});
|
});
|
||||||
match map
|
match map.into_values().sorted_by(|a, &b| b.cmp(a)).as_slice() {
|
||||||
.into_values()
|
|
||||||
.sorted_by(|a, &b| b.cmp(a))
|
|
||||||
.as_slice()
|
|
||||||
{
|
|
||||||
[5, ..] => Self::FiveOfAKind,
|
[5, ..] => Self::FiveOfAKind,
|
||||||
[4, ..] => Self::FourOfAKind,
|
[4, ..] => Self::FourOfAKind,
|
||||||
[3, 2, ..] => Self::FullHouse,
|
[3, 2, ..] => Self::FullHouse,
|
||||||
|
|||||||
@@ -101,16 +101,15 @@ enum HandType {
|
|||||||
|
|
||||||
impl From<&Hand> for HandType {
|
impl From<&Hand> for HandType {
|
||||||
fn from(value: &Hand) -> Self {
|
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.entry(card).and_modify(|c| *c += 1).or_insert(1);
|
||||||
acc
|
acc
|
||||||
});
|
});
|
||||||
let jokers = map.remove(&Card::Joker).unwrap_or(0);
|
let jokers = map.remove(&Card::Joker).unwrap_or(0);
|
||||||
match map
|
match map.into_values().sorted_by(|a, &b| b.cmp(a)).as_slice() {
|
||||||
.into_values()
|
|
||||||
.sorted_by(|a, &b| b.cmp(a))
|
|
||||||
.as_slice()
|
|
||||||
{
|
|
||||||
[x, ..] if jokers + x == 5 => Self::FiveOfAKind,
|
[x, ..] if jokers + x == 5 => Self::FiveOfAKind,
|
||||||
[] if jokers == 5 => Self::FiveOfAKind,
|
[] if jokers == 5 => Self::FiveOfAKind,
|
||||||
[x, ..] if jokers + x == 4 => Self::FourOfAKind,
|
[x, ..] if jokers + x == 4 => Self::FourOfAKind,
|
||||||
|
|||||||
Reference in New Issue
Block a user