summaryrefslogtreecommitdiff
path: root/19.c
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-30 12:00:07 +0000
committerAdam Spragg <adam@spra.gg>2022-12-30 12:00:07 +0000
commitd9ce5d31b273328be1d5d47f3e8608fcb2de18b1 (patch)
tree0bae129073fa1fb207ed9607641d2ce95207416b /19.c
parent48cfcf8ac657965848b713280715754af381d395 (diff)
Puzzle 19: Allow user to specify number of rounds
Diffstat (limited to '19.c')
-rw-r--r--19.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/19.c b/19.c
index 5be2d15..b3475f1 100644
--- a/19.c
+++ b/19.c
@@ -2,6 +2,7 @@
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#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);
}