Day 2 Part 2 Complete :)

This commit is contained in:
Luke Else 2023-12-04 18:52:58 +00:00
parent 6bd170cbde
commit 34c8099720

View File

@ -1,4 +1,4 @@
use std::{borrow::BorrowMut, collections::HashMap};
use std::{borrow::BorrowMut, collections::HashMap, fs::copy, vec};
use super::Solution;
@ -37,20 +37,23 @@ impl Solution for Day04 {
.enumerate()
.collect();
for card in cards {}
// for (i, card) in cards.iter() {
// let winning_nums = self.get_count_winning_numbers(card)?;
// if winning_nums == 0 {
// continue;
// }
// for c in cards.clone()[(i + 1)..=(i + 1 + winning_nums)].iter() {
// cards.push(c.clone());
// }
// }
// for i in cards.clone() {
// println!("{:?}", i);
// }
Ok(Box::new(cards.len()))
let mut copy_counts: Vec<u32> = vec![1; cards.len()];
for (i, card) in cards.iter() {
// Create a container for the cards
// Check if we are looking at a winning card
let winning_nums = self.get_count_winning_numbers(card)?;
if winning_nums == 0 { continue; }
// We have a winning card... add the next cards resulting * num of current card
for j in 0..winning_nums {
// Don't let us add cards that aren't available
copy_counts[*i + j + 1] += copy_counts[*i];
}
}
Ok(Box::new(copy_counts.iter().sum::<u32>()))
}
fn get_day(&self) -> u8 {