From 7b3e48d29d080d2cd9b57258f670c18f6fefc7aa Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Sun, 1 Dec 2024 04:15:38 -0500 Subject: cleanup --- 2023/rs/code/four/src/bin/maddie.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 2023/rs/code/four/src/bin/maddie.rs (limited to '2023/rs/code/four/src') 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 = 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}"); +} -- cgit v1.2.3-70-g09d2