use std::fs::File; use std::io::{self, BufRead}; use std::path::Path; use std::collections::HashSet; pub fn part_one() { if let Ok(lines) = read_lines("./input.txt") { let mut result = 0; for line in lines { result += process_line(&line.unwrap()); } println!("{}", result); } } fn process_line(s: &str) -> u32 { let mut winning_numbers = HashSet::new(); let mut res = 0; let nums_str: Vec<&str> = s.split(':').collect::>()[1].split('|').collect(); let w_str = nums_str[0].trim().split_whitespace().collect::>(); let w_nums: Vec = w_str.iter().map(|s| s.parse::().unwrap()).collect(); for n in w_nums { winning_numbers.insert(n); } let b_str = nums_str[1].trim().split_whitespace().collect::>(); let b_nums: Vec = b_str.iter().map(|s| s.parse::().unwrap()).collect(); for n in b_nums { if winning_numbers.contains(&n) { if res == 0 { res = 1; } else { res *= 2; } } } return res; } fn read_lines

(filename: P) -> io::Result>> where P: AsRef, { let file = File::open(filename)?; Ok(io::BufReader::new(file).lines()) }