summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-30 12:07:20 +0000
committerAdam Spragg <adam@spra.gg>2022-12-30 12:07:20 +0000
commit670ef721b13e907a1da915080b146b9e7dc1c3b8 (patch)
tree2dfc6040393e72af781ed2b7b94cc6a970f6c2ad
parentd9ce5d31b273328be1d5d47f3e8608fcb2de18b1 (diff)
Puzzle 19: Allow user to specify build strategy
-rw-r--r--19.c17
1 files 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 <regex.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
@@ -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);
}