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]
part2 = []
# default = ["part2"]
default = ["part2"]

View file

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