From d9ce5d31b273328be1d5d47f3e8608fcb2de18b1 Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Fri, 30 Dec 2022 12:00:07 +0000 Subject: Puzzle 19: Allow user to specify number of rounds --- 19.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to '19.c') diff --git a/19.c b/19.c index 5be2d15..b3475f1 100644 --- a/19.c +++ b/19.c @@ -2,6 +2,7 @@ #include #include #include +#include #define arrlen(x) (sizeof(x)/sizeof((x)[0])) @@ -177,11 +178,25 @@ inventory_build_basic(struct inventory * i, struct blueprint const * b, int rema int -main() +main(int argc, char ** argv) { + int rounds = 24; + int i; regex_t reblueprint; char buf[BUFSIZ]; + while ((i = getopt(argc, argv, "r:")) != -1) + { + switch (i) { + case 'r': + rounds = atoi(optarg); + break; + + default: + return -1; + } + } + if (regcomp(&reblueprint, "Blueprint ([[:digit:]]+):" " Each ore robot costs ([[:digit:]]+) ore." " Each clay robot costs ([[:digit:]]+) ore." @@ -214,7 +229,7 @@ main() inventory_init(&i); - inventory_build_basic(&i, &b, 24); + inventory_build_basic(&i, &b, rounds); printf("Blueprint %d geodes = %ld\n", b.id, i.geod.amount); } -- cgit v1.2.1