diff options
author | Aleteoryx <alyx@aleteoryx.me> | 2024-12-01 04:15:38 -0500 |
---|---|---|
committer | Aleteoryx <alyx@aleteoryx.me> | 2024-12-01 04:15:38 -0500 |
commit | 7b3e48d29d080d2cd9b57258f670c18f6fefc7aa (patch) | |
tree | 6ab125b5e8f1cf01c8941e5d8b6bc820b81364de /2023/rs/code | |
parent | da56199bf47557114a167877301d1ea28010448d (diff) | |
download | adventofcode-7b3e48d29d080d2cd9b57258f670c18f6fefc7aa.tar.gz adventofcode-7b3e48d29d080d2cd9b57258f670c18f6fefc7aa.tar.bz2 adventofcode-7b3e48d29d080d2cd9b57258f670c18f6fefc7aa.zip |
cleanup
Diffstat (limited to '2023/rs/code')
-rw-r--r-- | 2023/rs/code/four/src/bin/maddie.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/2023/rs/code/four/src/bin/maddie.rs b/2023/rs/code/four/src/bin/maddie.rs new file mode 100644 index 0000000..dc630a3 --- /dev/null +++ b/2023/rs/code/four/src/bin/maddie.rs @@ -0,0 +1,34 @@ +use std::fs; + +fn main() { + let puzzle_input: String = fs::read_to_string("src/input.txt").expect("Failed to read file"); + let mut total_points = 0; + let mut total_cards = 0; + let mut card_counts: Vec<i32> = vec![1;209]; + + for (i,line) in puzzle_input.lines().enumerate() { + let mut trim = line.split(":"); + trim.next(); + let mut nums = trim.next().unwrap().split("|"); + let winning_nums = nums.next().unwrap().split(" "); + let player_nums = nums.next().unwrap().split(" "); + let mut winning_num_count = 0; + + for num in player_nums { + for winning_num in winning_nums.clone() { + if num == winning_num && num != "" { + winning_num_count += 1; + } + } + } + if winning_num_count != 0 { + total_points += 1 << (winning_num_count-1); + } + for j in (i+1)..(i+winning_num_count+1) { + card_counts[j] += card_counts[i]; + } + total_cards += card_counts[i]; + } + println!("total points: {total_points}"); + println!("total cards: {total_cards}"); +} |