aoc-2019-c

git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

commit bdb93446e25e46a3cf9356d1df84973dfeab863a
parent 9a77efd40045b6698167f35d0b6a7dafb076b1b6
Author: Louis Burda <quent.burda@gmail.com>
Date:   Fri, 17 Mar 2023 16:47:21 +0100

Fixup day 4

Diffstat:
A.gdb_history | 5+++++
A04/.gdb_history | 2++
D04/Makefile | 12------------
A04/info.mk | 2++
M04/main.c | 16++++++++++------
5 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/.gdb_history b/.gdb_history @@ -0,0 +1,5 @@ +c +r +context +set follow-fork-mode child +r diff --git a/04/.gdb_history b/04/.gdb_history @@ -0,0 +1,2 @@ +r +f 399 diff --git a/04/Makefile b/04/Makefile @@ -1,12 +0,0 @@ -CFLAGS = -g -I ../../libs/include -L ../../libs/build -LDLIBS = -laoc - -all: lib main - -clean: - rm main - -lib: - make -C ../../libs - -main: main.c diff --git a/04/info.mk b/04/info.mk @@ -0,0 +1,2 @@ +04_SRC = 04/main.c common/main.c common/aoc.c common/util.c +04_HDR = common/aoc.h common/util.h diff --git a/04/main.c b/04/main.c @@ -1,5 +1,7 @@ #include "aoc.h" +#include "util.h" +#include <string.h> #include <stdlib.h> #include <stdio.h> @@ -12,7 +14,7 @@ check_pass_1(int *state) if (state[i] == state[i+1]) break; - if (i != 5) debug("%i %i %i %i %i %i\n", state[0], state[1], + if (i != 5) aoc_debug("%i %i %i %i %i %i\n", state[0], state[1], state[2], state[3], state[4], state[5]); return i != 5; @@ -29,7 +31,7 @@ check_pass_2(int *state) break; } - if (i != 5) debug("%i %i %i %i %i %i\n", state[0], state[1], + if (i != 5) aoc_debug("%i %i %i %i %i %i\n", state[0], state[1], state[2], state[3], state[4], state[5]); return i != 5; @@ -78,14 +80,15 @@ part1(void) char *tok; int count; - tok = CHKP(strchr(aoc.input, '-')); + tok = strchr(aoc.input, '-'); + if (!tok) die("main: bad input"); read_state(aoc.input, start); read_state(tok+1, end); count = 0; count_valid(start, end, 1, 1, 0, &count, check_pass_1); - aoc.answer = CHKP(aprintf("%i", count)); + aoc.answer = aprintf("%i", count); aoc.solution = "966"; } @@ -96,13 +99,14 @@ part2(void) char *tok; int count; - tok = CHKP(strchr(aoc.input, '-')); + tok = strchr(aoc.input, '-'); + if (!tok) die("main: bad input"); read_state(aoc.input, start); read_state(tok+1, end); count = 0; count_valid(start, end, 1, 1, 0, &count, check_pass_2); - aoc.answer = CHKP(aprintf("%i", count)); + aoc.answer = aprintf("%i", count); aoc.solution = "628"; }