From aadb672532b457c9aebcd34af158c4295aea96c0 Mon Sep 17 00:00:00 2001 From: Tobias Marschner Date: Wed, 10 Apr 2024 09:56:02 +0200 Subject: [PATCH] Touches on 2022/day19-part1 --- 2022/day19-part1/src/main.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/2022/day19-part1/src/main.rs b/2022/day19-part1/src/main.rs index eed6914..cdea3b0 100644 --- a/2022/day19-part1/src/main.rs +++ b/2022/day19-part1/src/main.rs @@ -13,6 +13,8 @@ struct Blueprint { optimal_geode_count: u16, } +const TOTAL_RUNTIME: usize = 24; + impl Blueprint { // Solve the given blueprint using BFS. fn solve_bfs(&mut self) { @@ -37,7 +39,7 @@ impl Blueprint { // Iterate over all timeslots. // Building a robot at t=1 cannot influence the final geode-count, // so it's omitted from the simulation here. - for ts in (2usize..=24).rev() { + for ts in (2usize..=TOTAL_RUNTIME).rev() { // println!("Now at {} remaining time. Processing {} input RSs ...", ts, next_hs.len()); // Process every RS of the past timeslot @@ -163,7 +165,7 @@ impl RecursionState { // Copy over states for the next simulation round, pruning a lot of (but not all) // RecursionStates that are "strictly inferior" in terms of Pareto optimality. -// Will clear any previously present elements in dest. +// Will clear any previously present elements in `dest`. // // A few words on the general idea here: // The goal here is to check for Pareto improvements. An example: @@ -182,9 +184,6 @@ fn prune_states(source: &mut [RecursionState], dest: &mut Vec) { // Begin by sorting the source lexicrgraphically and clearing the destination. source.sort_unstable(); dest.clear(); - // Add one more element to the source, at the very end, - // that is a copy of the last element +1 ore. - // This is to ensure that the actual last element // Iterate through it from smallest to largest element and look at every pair of states. for (a, b) in source.iter().zip(source.iter().skip(1)) { // Don't copy a over if it is strictly inferior or equal to b. @@ -201,7 +200,7 @@ fn prune_states(source: &mut [RecursionState], dest: &mut Vec) { dest.push(*a); } } - // Copy over the very last element, guaranteed to be part of the frontier. + // Copy over the very last element, too. dest.push(*source.last().unwrap()); } @@ -235,7 +234,7 @@ fn main() { // Solve for every blueprint. for bp in &mut blueprints { - // Solve every blueprint with 24 minutes of time. + // Solve every blueprint with TOTAL_RUNTIME minutes of time. println!("Solving Blueprint {}", bp.id); bp.solve_bfs(); }