use std::collections::HashSet; #[path = "../lib.rs"] mod lib; fn parse() -> Option> { let mut matches = vec![]; for line in lib::iter_input() { let (_, numbers) = line.split_once(": ")?; let (winning, have) = numbers.split_once(" | ")?; let w = winning .trim() .split_whitespace() .map(|s| s.parse::().unwrap()) .collect::>(); let h = have .trim() .split_whitespace() .map(|s| s.parse::().unwrap()) .collect::>(); matches.push(w.intersection(&h).count()); } return Some(matches); } fn part1(matches: &Vec) -> u32 { return matches .iter() .map(|x| if *x > 0 { 2_u32.pow(*x as u32 - 1) } else { 0 }) .sum::(); } fn part2(matches: &Vec) -> usize { let mut counts = vec![]; for _ in 0..matches.len() { counts.push(1); } for i in 0..matches.len() { for j in 0..matches[i] { counts[i + j + 1] += counts[i]; } } return counts.iter().sum(); } fn main() { let matches = parse().unwrap(); println!("part1: {}", part1(&matches)); println!("part2: {}", part2(&matches)); }