From a51a6be8d5f1614e0cdf696c2d1cb57354a1c500 Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Sat, 31 Dec 2022 17:36:42 +0000 Subject: Puzzle 19: Solve part 2 --- 19.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file 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); -- cgit v1.2.1