summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-31 17:36:42 +0000
committerAdam Spragg <adam@spra.gg>2022-12-31 17:36:42 +0000
commita51a6be8d5f1614e0cdf696c2d1cb57354a1c500 (patch)
treed162f1a58ef6fc4c1861107d56c23e8ff49df885
parent583046b8aba49d8a7da9055cbab762e921313fcc (diff)
Puzzle 19: Solve part 2
-rw-r--r--19.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/19.c b/19.c
index 2a86c26..c1740e2 100644
--- a/19.c
+++ b/19.c
@@ -303,18 +303,41 @@ int
main(int argc, char ** argv)
{
int rounds = 24;
- char const * build = "exhaustive";
+ char const * build = "exhaustive", * output = "quality";
int quality = 0, i;
+ long product = 1;
regex_t reblueprint;
char buf[BUFSIZ];
- while ((i = getopt(argc, argv, "b:r:")) != -1)
+ while ((i = getopt(argc, argv, "p:b:o:r:")) != -1)
{
switch (i) {
+ case 'p':
+ switch (atoi(optarg)) {
+ case 1:
+ rounds = 24;
+ output = "quality";
+ break;
+
+ case 2:
+ rounds = 32;
+ output = "product";
+ break;
+
+ default:
+ fprintf(stderr, "Unexpected puzzle part: %s\n", optarg);
+ return -1;
+ }
+ break;
+
case 'b':
build = optarg;
break;
+ case 'o':
+ output = optarg;
+ break;
+
case 'r':
rounds = atoi(optarg);
break;
@@ -378,12 +401,23 @@ main(int argc, char ** argv)
}
quality += b.id * i.geod.amount;
+ product *= i.geod.amount;
#if 0
fprintf(stderr, "Blueprint %d geodes = %d\n", b.id, i.geod.amount);
#endif
}
- printf("Total quality level = %d\n", quality);
+ if (strcmp(output, "quality") == 0) {
+ printf("Total quality level = %d\n", quality);
+ }
+ else if (strcmp(output, "product") == 0) {
+ printf("Total geode product = %ld\n", product);
+ }
+ else {
+ fprintf(stderr, "Unknown output type: %s\n", output);
+ regfree(&reblueprint);
+ return -1;
+ }
regfree(&reblueprint);