diff options
-rw-r--r-- | 19.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -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); } |