day 7 part 2 hates me

This commit is contained in:
RingOfStorms (Joshua Bell) 2023-12-08 02:36:49 -06:00
parent 82fc810e11
commit c67235eb46
2 changed files with 42 additions and 34 deletions

View file

@ -31,4 +31,4 @@ static_init = "1.0.3"
[features] [features]
part2 = [] part2 = []
# default = ["part2"] default = ["part2"]

View file

@ -23,16 +23,22 @@ impl Strength {
// let mut counts = [0; 14]; let mut jokers = 0; // let mut counts = [0; 14]; let mut jokers = 0;
for card in hand.cards.iter() { for card in hand.cards.iter() {
if card == &1 { if card == &1 {
for possible_count in possible_counts.iter() {} let mut new_possible_counts: Vec<[i32; 14]> = vec![];
jokers += 1; for possible_count in possible_counts.iter() {
for i in 0..14 {
let mut new_counts = possible_count.clone();
new_counts[i] += 1;
new_possible_counts.push(new_counts);
}
}
possible_counts = new_possible_counts;
} else { } else {
for counts in possible_counts.iter_mut() {
counts[*card as usize - 2] += 1; counts[*card as usize - 2] += 1;
} }
} }
}
// CURRENT BUG is that the jokers are adding to all counts so the counts are "off" possible_counts.iter().map(|counts| {
// for possible real hands like full house etc, need to branch off and try all
// combinations...
counts.iter().fold(Strength::HighCard, |strength, &count| { counts.iter().fold(Strength::HighCard, |strength, &count| {
std::cmp::max( std::cmp::max(
strength.clone(), strength.clone(),
@ -53,6 +59,7 @@ impl Strength {
}, },
) )
}) })
}).sorted().next().unwrap()
} }
#[cfg(not(feature = "part2"))] #[cfg(not(feature = "part2"))]
@ -161,16 +168,17 @@ fn calculate(input: String) -> Result<usize> {
let answer = input let answer = input
.lines() .lines()
.map(|line| line.parse::<Hand>().unwrap()) .map(|line| line.parse::<Hand>().unwrap())
.sorted() .sorted().collect_vec();
.enumerate() // .enumerate()
.map(|(idx, hand)| hand.bid * (idx + 1)) // .map(|(idx, hand)| hand.bid * (idx + 1))
.sum(); // .sum();
let algo_time = start.elapsed(); let algo_time = start.elapsed();
// ``` // ```
// for i in answer { for i in answer {
// println!("{:?}: {:?}", i, Strength::for_hand(&i.1)); println!("{:?}: {:?}", i, Strength::for_hand(&i));
// } }
let answer = 0;
// ``` // ```
// //
// output // output