| fn main() { |
| let input = include_str!("../input.txt"); |
| |
| let mut part1_possible_id_sum = 0; |
| let mut game_power_sum = 0; |
| |
| for (index, line) in input.split('\n').enumerate() { |
| if line == "" { |
| continue; |
| } |
| |
| let game_data = line.split(": ").collect::<Vec<&str>>()[1]; |
| |
| let mut part1_possible = true; |
| let mut min_red = 0; |
| let mut min_green = 0; |
| let mut min_blue = 0; |
| |
| for round in game_data.split("; ") { |
| |
| for draw in round.split(", ") { |
| let [number_as_text, color] = draw.split(" ").collect::<Vec<&str>>()[..] else { panic!("Unparseable draw") }; |
| |
| let number = number_as_text.parse::<i32>().unwrap(); |
| |
| match color { |
| "red" => { |
| if number > 12 { |
| part1_possible = false; |
| } |
| if number > min_red { |
| min_red = number; |
| } |
| }, |
| "green" => { |
| if number > 13 { |
| part1_possible = false; |
| } |
| if number > min_green { |
| min_green = number; |
| } |
| }, |
| "blue" => { |
| if number > 14 { |
| part1_possible = false; |
| } |
| if number > min_blue { |
| min_blue = number; |
| } |
| }, |
| noncolor => { |
| panic!("bogus color {}", noncolor); |
| } |
| } |
| } |
| } |
| |
| if part1_possible { |
| part1_possible_id_sum += index + 1; |
| println!("Game {} is possible with 12, 13, 14", index + 1); |
| } else { |
| println!("Game {} is not possible with 12, 13, 14", index + 1); |
| } |
| |
| let game_power = min_red * min_green * min_blue; |
| game_power_sum += game_power; |
| println!("Game {} has power {}", index + 1, game_power); |
| } |
| |
| println!("Possible with 12, 13, 14 ID sum: {}", part1_possible_id_sum); |
| println!("Game power sum: {}", game_power_sum); |
| } |