advent2021

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

commit d8889b75c487f2b875005d14c2e794329c55fa9b
parent 51c0568fca5e7912677c7c770332129e643c0230
Author: bsandro <brian.drosan@gmail.com>
Date:   Sat, 11 Dec 2021 16:18:59 +0200

Small clean up

Diffstat:
Rrun.sh -> all.sh | 0
Mday01/main.c | 5+++++
Mday02/main.c | 5+++++
Mday03/main.c | 5+++++
Mday04/main.c | 5+++++
Mday04/puzzle12.c | 6------
6 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/run.sh b/all.sh diff --git a/day01/main.c b/day01/main.c @@ -1,10 +1,12 @@ #include <stdio.h> +#include <time.h> int puzzle1(const char *filename); int puzzle2(const char *filename); int main(int argc, char *argv[]) { printf("Advent of Code: day 01\n"); + double time_start = clock(); if (argc <= 0) { return -1; @@ -21,5 +23,8 @@ int main(int argc, char *argv[]) { int counter2 = puzzle2(filename); printf("Puzzle #2: %d\n", counter2); + double elapsed = clock() - time_start; + printf("Elapsed: %f\n", elapsed / CLOCKS_PER_SEC); + return 0; } diff --git a/day02/main.c b/day02/main.c @@ -1,10 +1,12 @@ #include <stdio.h> +#include <time.h> int puzzle1(const char *filename); int puzzle2(const char *filename); int main(int argc, char *argv[]) { printf("Advent of Code: day 02\n"); + double time_start = clock(); if (argc <= 0) { return -1; @@ -21,5 +23,8 @@ int main(int argc, char *argv[]) { int counter2 = puzzle2(filename); printf("Puzzle #2: %d\n", counter2); + double elapsed = clock() - time_start; + printf("Elapsed: %f\n", elapsed / CLOCKS_PER_SEC); + return 0; } diff --git a/day03/main.c b/day03/main.c @@ -1,10 +1,12 @@ #include <stdio.h> +#include <time.h> int puzzle1(const char *filename); int puzzle2(const char *filename); int main(int argc, char *argv[]) { printf("Advent of Code: day 03\n"); + double time_start = clock(); if (argc <= 0) { return -1; @@ -21,5 +23,8 @@ int main(int argc, char *argv[]) { int counter2 = puzzle2(filename); printf("Puzzle #2: %d\n", counter2); + double elapsed = clock() - time_start; + printf("Elapsed: %f\n", elapsed / CLOCKS_PER_SEC); + return 0; } diff --git a/day04/main.c b/day04/main.c @@ -1,9 +1,11 @@ #include <stdio.h> +#include <time.h> void puzzle(const char *filename, int *res1, int *res2); int main(int argc, char *argv[]) { printf("Advent of Code: day 04\n"); + double time_start = clock(); if (argc <= 0) { return -1; @@ -23,5 +25,8 @@ int main(int argc, char *argv[]) { printf("Puzzle #1: %d\n", counter1); printf("Puzzle #2: %d\n", counter2); + double elapsed = clock() - time_start; + printf("Elapsed: %f\n", elapsed / CLOCKS_PER_SEC); + return 0; } diff --git a/day04/puzzle12.c b/day04/puzzle12.c @@ -7,7 +7,6 @@ #include <strings.h> #include <stdbool.h> #include <assert.h> -#include <time.h> #include "util.h" @@ -29,8 +28,6 @@ void print_boards(const struct array_t *boards); /* ****************************************************************** */ void puzzle(const char *filename, int *result1, int *result2) { - double time_start = clock(); - FILE *infile = fopen(filename, "r"); if (infile == NULL) { fprintf(stderr, "fopen() error: %s\n", strerror(errno)); @@ -103,9 +100,6 @@ void puzzle(const char *filename, int *result1, int *result2) { free(numbers.data); free(boards.data); fclose(infile); - - double elapsed = clock() - time_start; - printf("elapsed: %f\n", elapsed / CLOCKS_PER_SEC); } /* ************************* BOILERPLATE ************************* */