Touches on 2022/day19-part1
This commit is contained in:
parent
0e1053ec5e
commit
aadb672532
@ -13,6 +13,8 @@ struct Blueprint {
|
|||||||
optimal_geode_count: u16,
|
optimal_geode_count: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TOTAL_RUNTIME: usize = 24;
|
||||||
|
|
||||||
impl Blueprint {
|
impl Blueprint {
|
||||||
// Solve the given blueprint using BFS.
|
// Solve the given blueprint using BFS.
|
||||||
fn solve_bfs(&mut self) {
|
fn solve_bfs(&mut self) {
|
||||||
@ -37,7 +39,7 @@ impl Blueprint {
|
|||||||
// Iterate over all timeslots.
|
// Iterate over all timeslots.
|
||||||
// Building a robot at t=1 cannot influence the final geode-count,
|
// Building a robot at t=1 cannot influence the final geode-count,
|
||||||
// so it's omitted from the simulation here.
|
// 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());
|
// println!("Now at {} remaining time. Processing {} input RSs ...", ts, next_hs.len());
|
||||||
|
|
||||||
// Process every RS of the past timeslot
|
// 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)
|
// 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.
|
// 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:
|
// A few words on the general idea here:
|
||||||
// The goal here is to check for Pareto improvements. An example:
|
// The goal here is to check for Pareto improvements. An example:
|
||||||
@ -182,9 +184,6 @@ fn prune_states(source: &mut [RecursionState], dest: &mut Vec<RecursionState>) {
|
|||||||
// Begin by sorting the source lexicrgraphically and clearing the destination.
|
// Begin by sorting the source lexicrgraphically and clearing the destination.
|
||||||
source.sort_unstable();
|
source.sort_unstable();
|
||||||
dest.clear();
|
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.
|
// 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)) {
|
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.
|
// 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<RecursionState>) {
|
|||||||
dest.push(*a);
|
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());
|
dest.push(*source.last().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +234,7 @@ fn main() {
|
|||||||
|
|
||||||
// Solve for every blueprint.
|
// Solve for every blueprint.
|
||||||
for bp in &mut blueprints {
|
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);
|
println!("Solving Blueprint {}", bp.id);
|
||||||
bp.solve_bfs();
|
bp.solve_bfs();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user