From 7c6b17c3e2e4976bcfa20751d5a1b6300906e69a Mon Sep 17 00:00:00 2001 From: Jur van den Berg Date: Mon, 19 Dec 2022 23:43:04 +0100 Subject: [PATCH] some minor pruning, but whatever --- src/day19.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/day19.rs b/src/day19.rs index 0e90b8e..a966066 100644 --- a/src/day19.rs +++ b/src/day19.rs @@ -113,32 +113,35 @@ fn find_best_geodes(bp: &Blueprint, time: usize) -> usize { obsidian: state.obsidian - bp.geode_bot_cost.1 + state.obsidian_bots, ..state.tick() }; - if visited.insert(next.clone()) { + if visited.insert(next) { stack.push(next); } } - // Obsidian bots are nice too - if state.ore >= bp.obsidian_bot_cost.0 && state.clay >= bp.obsidian_bot_cost.1 { + // Obsidian bots are nice too, unless we have enough + if state.ore >= bp.obsidian_bot_cost.0 + && state.clay >= bp.obsidian_bot_cost.1 + && state.obsidian_bots < bp.geode_bot_cost.1 + { let next = State { obsidian_bots: state.obsidian_bots + 1, ore: state.ore - bp.obsidian_bot_cost.0 + state.ore_bots, clay: state.clay - bp.obsidian_bot_cost.1 + state.clay_bots, ..state.tick() }; - if visited.insert(next.clone()) { + if visited.insert(next) { stack.push(next); } } - // Clay? - if state.ore >= bp.clay_bot_cost { + // Clay? also prune if we have enough for obsidian bots + if state.ore >= bp.clay_bot_cost && state.clay_bots < bp.obsidian_bot_cost.1 { let next = State { clay_bots: state.clay_bots + 1, ore: state.ore - bp.clay_bot_cost + state.ore_bots, ..state.tick() }; - if visited.insert(next.clone()) { + if visited.insert(next) { stack.push(next); } } @@ -150,14 +153,14 @@ fn find_best_geodes(bp: &Blueprint, time: usize) -> usize { ore: state.ore - bp.ore_bot_cost + state.ore_bots, ..state.tick() }; - if visited.insert(next.clone()) { + if visited.insert(next) { stack.push(next); } } // Final option, do nothing let next = state.tick(); - if visited.insert(next.clone()) { + if visited.insert(next) { stack.push(next); } }