aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

commit 65dd777ed0a54091f5dcb8a9b83a4c34c6bbef3b
parent 50b41d675539987dc9402de6f33a545c9732594b
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sat,  5 Jul 2025 00:23:38 +0200

Revert wrong optimization

Diffstat:
M2022/19/a.rs | 2+-
M2022/19/common.rs | 18++++++------------
2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/2022/19/a.rs b/2022/19/a.rs @@ -8,7 +8,7 @@ fn main() { let mut i = 1; let mut sum = 0; for bp in read_blueprints_from_stdin() { - let mg = most_geodes(&bp, Status::new(), MINUTES, &mut mem, 0); + let mg = most_geodes(&bp, Status::new(), MINUTES, &mut mem); println!("{i}: {mg}"); sum += i * mg; mem.clear(); diff --git a/2022/19/common.rs b/2022/19/common.rs @@ -122,17 +122,11 @@ pub fn most_geodes( bp: &Blueprint, s: Status, m: i32, - mem: &mut HashMap<(Status, i32), i32>, - lower_bound: i32 + mem: &mut HashMap<(Status, i32), i32> ) -> i32 { if m == 0 { return s.resources.geo; } if m == 1 { return s.resources.geo + s.bots.geo; } - // Estimate how much we can get at most, assuming one geode bot - // can be built each turn from now on - let upper_bound = s.resources.geo + s.bots.geo + (m-1)*(m-2)/2; - if upper_bound <= lower_bound { return 0; } - if let Some(r) = mem.get(&(s, m)) { return *r; } let mut new_status = s; @@ -143,7 +137,7 @@ pub fn most_geodes( if m > 1 && s.resources >= bp.geo_bot_cost { new_status.resources -= &bp.geo_bot_cost; new_status.bots.geo += 1; - result = most_geodes(bp, new_status, m-1, mem, result); + result = most_geodes(bp, new_status, m-1, mem); // If a geode bot can be built, it is always the best thing to do mem.insert((s, m), result); @@ -153,7 +147,7 @@ pub fn most_geodes( if m > 2 && s.resources >= bp.obs_bot_cost { new_status.resources -= &bp.obs_bot_cost; new_status.bots.obs += 1; - result = max(result, most_geodes(bp, new_status, m-1, mem, result)); + result = max(result, most_geodes(bp, new_status, m-1, mem)); new_status.bots.obs -= 1; new_status.resources += &bp.obs_bot_cost; } @@ -161,7 +155,7 @@ pub fn most_geodes( if m > 3 && s.resources >= bp.cla_bot_cost { new_status.resources -= &bp.cla_bot_cost; new_status.bots.cla += 1; - result = max(result, most_geodes(bp, new_status, m-1, mem, result)); + result = max(result, most_geodes(bp, new_status, m-1, mem)); new_status.bots.cla -= 1; new_status.resources += &bp.cla_bot_cost; } @@ -169,12 +163,12 @@ pub fn most_geodes( if m > 4 && s.resources >= bp.ore_bot_cost { new_status.resources -= &bp.ore_bot_cost; new_status.bots.ore += 1; - result = max(result, most_geodes(bp, new_status, m-1, mem, result)); + result = max(result, most_geodes(bp, new_status, m-1, mem)); new_status.bots.ore -= 1; new_status.resources += &bp.ore_bot_cost; } - result = max(result, most_geodes(bp, new_status, m-1, mem, result)); + result = max(result, most_geodes(bp, new_status, m-1, mem)); mem.insert((s, m), result); result