diff --git a/2023/day2/src/main.rs b/2023/day2/src/main.rs index d8e0339..a08f828 100644 --- a/2023/day2/src/main.rs +++ b/2023/day2/src/main.rs @@ -45,11 +45,11 @@ impl Game { .map_err(|e| format!("could not parse game id \"{id}\": {e}"))? }; - for draw in draws.split(";").map(|s| s.trim()) { + for draw in draws.split(';').map(|s| s.trim()) { let mut colors: HashMap = HashMap::new(); - for color in draw.split(",").map(|s| s.trim()) { + for color in draw.split(',').map(|s| s.trim()) { let (count, color) = color - .split_once(" ") + .split_once(' ') .ok_or("count and color were not separated by space")?; let color: Color = color.try_into()?; let count = count @@ -58,7 +58,7 @@ impl Game { // insert returns Some(old_value) if the value as already present, this // is treated as an error - if let Some(_) = colors.insert(color, count) { + if colors.insert(color, count).is_some() { return Err("color seen more than once".into()); } } @@ -93,11 +93,11 @@ fn parse_input(input: &str) -> Result, String> { input .lines() .map(|line| line.trim()) - .map(|line| Game::parse(line)) + .map(Game::parse) .collect::, String>>() } -fn count_possible_games(games: &Vec, limits: &HashMap) -> Result { +fn count_possible_games(games: &[Game], limits: &HashMap) -> Result { Ok(games .iter() .filter_map(|game| { @@ -117,9 +117,9 @@ fn count_possible_games(games: &Vec, limits: &HashMap) -> Resu .sum()) } -fn minimum_cube_powered(games: &Vec) -> Result { +fn minimum_cube_powered(games: &[Game]) -> Result { Ok(games - .into_iter() + .iter() .map(|game| game.minimum_cube_count()) .map(|counts| counts.into_values().product::()) .sum())