From 670ef721b13e907a1da915080b146b9e7dc1c3b8 Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Fri, 30 Dec 2022 12:07:20 +0000 Subject: Puzzle 19: Allow user to specify build strategy --- 19.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/19.c b/19.c index b3475f1..5e9e485 100644 --- a/19.c +++ b/19.c @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -181,13 +182,18 @@ int main(int argc, char ** argv) { int rounds = 24; + char const * build = "basic"; int i; regex_t reblueprint; char buf[BUFSIZ]; - while ((i = getopt(argc, argv, "r:")) != -1) + while ((i = getopt(argc, argv, "b:r:")) != -1) { switch (i) { + case 'b': + build = optarg; + break; + case 'r': rounds = atoi(optarg); break; @@ -229,7 +235,14 @@ main(int argc, char ** argv) inventory_init(&i); - inventory_build_basic(&i, &b, rounds); + if (strcmp(build, "basic") == 0) { + inventory_build_basic(&i, &b, rounds); + } + else { + fprintf(stderr, "Unknown build strategy: %s\n", build); + regfree(&reblueprint); + return -1; + } printf("Blueprint %d geodes = %ld\n", b.id, i.geod.amount); } -- cgit v1.2.1