From e906454afbff5ccf9771758d335010d5fb2ab48a Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Sat, 17 Dec 2022 21:10:51 +0000 Subject: Allow variable time until eruption --- 16.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/16.c b/16.c index bff6c6a..da78368 100644 --- a/16.c +++ b/16.c @@ -221,7 +221,7 @@ valve_distance(struct valve * valves, int nvalves, int * dists, struct valve con int main(int argc, char ** argv) { - int debug = 0, i; + int debug = 0, eruption = 30, i; regex_t valvein; regmatch_t rmvalve[4]; char buf[BUFSIZ]; @@ -236,12 +236,17 @@ main(int argc, char ** argv) return -1; } - while ((i = getopt(argc, argv, "d")) != -1) { + while ((i = getopt(argc, argv, "dt:")) != -1) { switch (i) { case 'd': debug = 1; break; + case 't': + // 'time' is taken by time(3), hence 'eruption' + eruption = atoi(optarg); + break; + default: return -1; } @@ -304,7 +309,7 @@ main(int argc, char ** argv) qsort(path + 1, nflows, sizeof(struct valve *), ptrcmp); do { struct valve ** pv; - int flow = 0, minutes = 30; + int flow = 0, minutes = eruption; // Calculate the flow of this permutation. for (pv = path + 1; pv < path + 1 + nflows && minutes > 0; ++pv) { -- cgit v1.2.1