summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-17 21:10:51 +0000
committerAdam Spragg <adam@spra.gg>2022-12-17 21:10:51 +0000
commite906454afbff5ccf9771758d335010d5fb2ab48a (patch)
tree100b5141b30d0ca91210b98f0ea4fbb69fdfebb8
parentbe31c082ce6ec6bf3ed5d4c4f6c8f460045a8757 (diff)
Allow variable time until eruption
-rw-r--r--16.c11
1 files 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) {