From a6c3d7b75d9a0a6530d8c17094a2d72a3ae8e109 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Tue, 5 Dec 2023 13:59:19 -0500 Subject: [PATCH] Day 2 complete --- day_2/src/main.rs | 37 +++++++++++++++++++++++++++++++++++++ day_3/Cargo.toml | 8 ++++++++ day_3/src/main.rs | 3 +++ 3 files changed, 48 insertions(+) create mode 100644 day_3/Cargo.toml create mode 100644 day_3/src/main.rs diff --git a/day_2/src/main.rs b/day_2/src/main.rs index bcb910c..12d4603 100644 --- a/day_2/src/main.rs +++ b/day_2/src/main.rs @@ -58,6 +58,43 @@ fn main() } println!("\nSum of valid game IDs: {}", sum); + + let mut power_sum = 0; + for game in games + { + let min_cubes = find_min_cubes_for_game(&game); + + let power_set = min_cubes.red * min_cubes.green * min_cubes.blue; // This could be made a method of CubeSample + // println!("DEBUG: Power Set: {}", power_set); + + power_sum += power_set; + } + + println!("Power sum of minimum cube sets: {}", power_sum); +} + +fn find_min_cubes_for_game(game: &Vec) -> CubeSample +{ + let mut min_cubes = CubeSample::new(); + for sample in game + { + if min_cubes.red < sample.red + { + min_cubes.red = sample.red; + } + + if min_cubes.green < sample.green + { + min_cubes.green = sample.green; + } + + if min_cubes.blue < sample.blue + { + min_cubes.blue = sample.blue; + } + } + + min_cubes } fn parse_games(game_data: &str) -> Vec> diff --git a/day_3/Cargo.toml b/day_3/Cargo.toml new file mode 100644 index 0000000..65c9609 --- /dev/null +++ b/day_3/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day_3" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day_3/src/main.rs b/day_3/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/day_3/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}