diff options
author | Adam Spragg <adam@spra.gg> | 2022-12-30 12:00:07 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-12-30 12:00:07 +0000 |
commit | d9ce5d31b273328be1d5d47f3e8608fcb2de18b1 (patch) | |
tree | 0bae129073fa1fb207ed9607641d2ce95207416b | |
parent | 48cfcf8ac657965848b713280715754af381d395 (diff) |
Puzzle 19: Allow user to specify number of rounds
-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); } |