From 29ff13fb86e24799d1805c21d46dfd47b6d27fee Mon Sep 17 00:00:00 2001 From: Candygoblen123 Date: Sat, 2 Dec 2023 22:11:35 -0500 Subject: [PATCH] day2part2 --- day2/src/main.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/day2/src/main.rs b/day2/src/main.rs index 422df23..39a1499 100644 --- a/day2/src/main.rs +++ b/day2/src/main.rs @@ -1,3 +1,37 @@ +use std::{fs, cmp::max}; + +fn main() { + let input = fs::read_to_string("input.txt").unwrap(); + let input: Vec<_> = input.split('\n').collect(); + let mut sum = 0; + for line in input { + let split:Vec<_> = line.split(':').collect(); + let rounds: Vec<_> = split.last().unwrap().split(';').collect(); + let rounds: Vec<_> = rounds.iter().map(|x| x.split(',').collect::>()).collect(); + let rounds: Vec<_> = rounds.iter().map(|x| x.iter().map(|x| x.trim().split(' ').collect::>()).collect::>()).collect(); + let (mut r_max, mut g_max, mut b_max) = (0, 0, 0); + for round in rounds { + for set in round { + let color = set.last().unwrap(); + let num: i32 = set.first().unwrap().parse().unwrap(); + match *color { + "red" => r_max = max(num, r_max), + "blue" => b_max = max(num, b_max), + "green" => g_max = max(num, g_max), + &_ => todo!() + } + } + + } + //println!("{}", r_max); + sum += r_max * g_max * b_max; + } + println!("{}", sum); + +} + + + // use std::fs; // fn main() {