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}"); }