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,36 +23,43 @@ 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 {
counts[*card as usize - 2] += 1; for counts in possible_counts.iter_mut() {
counts[*card as usize - 2] += 1;
}
} }
} }
possible_counts.iter().map(|counts| {
// CURRENT BUG is that the jokers are adding to all counts so the counts are "off" counts.iter().fold(Strength::HighCard, |strength, &count| {
// for possible real hands like full house etc, need to branch off and try all std::cmp::max(
// combinations... strength.clone(),
counts.iter().fold(Strength::HighCard, |strength, &count| { match count {
std::cmp::max( 5 => Strength::FiveOfAKind,
strength.clone(), 4 => Strength::FourOfAKind,
match count { 3 => match strength {
5 => Strength::FiveOfAKind, Strength::TwoPair => Strength::FullHouse,
4 => Strength::FourOfAKind, Strength::OnePair => Strength::FullHouse,
3 => match strength { _ => Strength::ThreeOfAKind,
Strength::TwoPair => Strength::FullHouse, },
Strength::OnePair => Strength::FullHouse, 2 => match strength {
_ => Strength::ThreeOfAKind, Strength::ThreeOfAKind => Strength::FullHouse,
Strength::OnePair => Strength::TwoPair,
_ => Strength::OnePair,
},
_ => strength,
}, },
2 => match strength { )
Strength::ThreeOfAKind => Strength::FullHouse, })
Strength::OnePair => Strength::TwoPair, }).sorted().next().unwrap()
_ => Strength::OnePair,
},
_ => strength,
},
)
})
} }
#[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