From 583046b8aba49d8a7da9055cbab762e921313fcc Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Sat, 31 Dec 2022 16:45:21 +0000 Subject: Puzzle 19: Don't build a type of robot if we have lots of that resource We obviously have enough of that resource at this time, so there's no need for another robot yet. Drops time by 60% on full 24-round test data (4.6s -> 1.8s) --- 19.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/19.c b/19.c index 2700712..2a86c26 100644 --- a/19.c +++ b/19.c @@ -256,6 +256,7 @@ inventory_build_exhaustive(struct inventory * i, struct blueprint const * b, int // Try building a obsidian robot, and checking if that's better than anything else if (i->bsdn.robots < b->max_bsdn + && i->bsdn.amount < 2 * b->max_bsdn && inventory_build(&test, b, BSDN) == 0) { // fprintf(stderr, "%d: building a bsdn robot (%ld)\n", remaining, test.bsdn.amount); @@ -268,6 +269,7 @@ inventory_build_exhaustive(struct inventory * i, struct blueprint const * b, int // Try building a clay robot, and checking if that's better than anything else if (i->clay.robots < b->max_clay + && i->clay.amount < 2 * b->max_clay && remaining > 5 && inventory_build(&test, b, CLAY) == 0) { @@ -281,6 +283,7 @@ inventory_build_exhaustive(struct inventory * i, struct blueprint const * b, int // Try building a ore robot, and checking if that's better than anything else if (i->ore.robots < b->max_ore + && i->ore.amount < 2 * b->max_ore && remaining > 10 && inventory_build(&test, b, ORE) == 0) { -- cgit v1.2.1