From bcfefb5a42fd977d1a775ce259b6ec09d66fa8ed Mon Sep 17 00:00:00 2001 From: Jeremy Kaplan Date: Mon, 26 Dec 2022 15:45:22 -0800 Subject: [PATCH] 2022 Day 19 Part 2 --- 2022/src/bin/day19.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/2022/src/bin/day19.rs b/2022/src/bin/day19.rs index 4fd2100..b686992 100644 --- a/2022/src/bin/day19.rs +++ b/2022/src/bin/day19.rs @@ -13,7 +13,8 @@ const INPUT: &str = include_str!("../../input/day19.txt"); fn main() { let blueprints: Vec = aoc::lines(INPUT).map(Blueprint::parse).collect(); - println!("{}", part1(blueprints)); + println!("{}", part1(&blueprints)); + println!("{}", part2(&blueprints[..3])); } #[derive(Debug, Clone)] @@ -92,15 +93,23 @@ impl FromStr for Resource { } } -fn part1(blueprints: Vec) -> u64 { +fn part1(blueprints: &[Blueprint]) -> u64 { blueprints .iter() .cloned() - .map(|bp| bp.id() * quality(bp, 24)) + .map(|bp| bp.id() * geodes_mined(bp, 24)) .sum() } -fn quality(blueprint: Blueprint, total_minutes: u64) -> u64 { +fn part2(blueprints: &[Blueprint]) -> u64 { + blueprints + .iter() + .cloned() + .map(|bp| geodes_mined(bp, 32)) + .product() +} + +fn geodes_mined(blueprint: Blueprint, total_minutes: u64) -> u64 { dbg!(&blueprint.id); let factory = Factory::new(blueprint);