diff options
| author | Adam Spragg <adam@spra.gg> | 2022-12-12 10:39:38 +0000 | 
|---|---|---|
| committer | Adam Spragg <adam@spra.gg> | 2022-12-12 10:39:38 +0000 | 
| commit | 638dacd5cd74637fb25a8dfdd516dc3b4d7a92f2 (patch) | |
| tree | c33737c21173f5dfa40ae927071a93323f57bf8e | |
| parent | 411c0f61756fad52d1d287d53b64149c71209829 (diff) | |
Solve puzzle 12 part 2
| -rw-r--r-- | 12.c | 20 | 
1 files changed, 18 insertions, 2 deletions
| @@ -2,6 +2,7 @@  #include <stdio.h>  #include <stdlib.h>  #include <string.h> +#include <unistd.h>  struct pos { @@ -86,14 +87,26 @@ tryvisit(unsigned char * range, int cols, int rows, struct pos const * from, int  int -main() +main(int argc, char ** argv)  { +	int part = 1;  	unsigned char * range, * p;  	size_t rangesize, rangelen, bytes;  	int cols, rows;  	struct pos * front;  	int steps; +	while ((steps = getopt(argc, argv, "p:")) != -1) { +		switch (steps) { +		case 'p': +			part = atoi(optarg); +			break; + +		default: +			return -1; +		} +	} +  	// Read hill range  	rangesize = BUFSIZ;  	rangelen = 0; @@ -141,9 +154,12 @@ main()  		struct pos * loc;  		for (loc = front; loc != NULL; loc = loc->next) { -			if ((range[loc->x + loc->y * cols] & 0x7F) == 'S') +			if (part == 1 && (range[loc->x + loc->y * cols] & 0x7F) == 'S')  				// We found the start point!  				break; +			if (part == 2 && height(range[loc->x + loc->y * cols]) == 'a') +				// We found a low point +				break;  			if (tryvisit(range, cols, rows, loc, -1, 0))  				nextfront = pos_create(loc->x - 1, loc->y, nextfront); | 
