advent2021

Advent of Code 2021 Solutions
git clone git://bsandro.tech/advent2021
Log | Files | Refs | README | LICENSE

main.c (985B)


      1 #include <stdio.h>
      2 #include <time.h>
      3 #include <string.h>
      4 
      5 void puzzle(const char *filename, long long *res1, long long *res2);
      6 void puzzle_test(const char *filename, long long *res1, long long *res2);
      7 
      8 int main(int argc, char *argv[]) {
      9 	printf("Advent of Code: day 09\n");
     10 	double time_start = clock();
     11 
     12 	if (argc <= 0) {
     13 		return -1;
     14 	}
     15 
     16 	if (argc == 1) {
     17 		printf("Usage: %s inputfile.txt\n", argv[0]);
     18 		return -1;
     19 	}
     20 
     21 	const char *filename = argv[1];
     22 	int is_test = 0;
     23 
     24 	if (argc == 2) {
     25 		filename = argv[1];
     26 	} else { // > 2
     27 		is_test = strlen(argv[1]) == 2 && strncmp(argv[1], "-t", 2) == 0;
     28 		filename = argv[2];
     29 	}
     30 
     31 	long long counter1 = -1;
     32 	long long counter2 = -1;
     33 
     34 	if (is_test) {
     35 		puzzle_test(filename, &counter1, &counter2);
     36 	} else {
     37 		puzzle(filename, &counter1, &counter2);
     38 	}
     39 
     40 	printf("Puzzle #1: %lld\n", counter1);
     41 	printf("Puzzle #2: %lld\n", counter2);
     42 
     43 	double elapsed = clock() - time_start;
     44 	printf("Elapsed: %f\n", elapsed / CLOCKS_PER_SEC);
     45 
     46 	return 0;
     47 }