From 7db946f06f30966f03ebcfcbf8d2abba13316f30 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Fri, 3 Dec 2021 10:12:21 +0100 Subject: [PATCH] rename, cleanup, improve makefile --- 1.txt => 01.txt | 0 01a.c | 31 +++++++++++++++++++++++++++++++ 01.c => 01b.c | 3 --- 1e.txt => 01e.txt | 0 2.txt => 02.txt | 0 02b.l | 2 +- 2e.txt => 02e.txt | 0 3.txt => 03.txt | 0 3e.txt => 03e.txt | 0 Makefile | 10 +++++++++- 10 files changed, 41 insertions(+), 5 deletions(-) rename 1.txt => 01.txt (100%) create mode 100644 01a.c rename 01.c => 01b.c (91%) rename 1e.txt => 01e.txt (100%) rename 2.txt => 02.txt (100%) rename 2e.txt => 02e.txt (100%) rename 3.txt => 03.txt (100%) rename 3e.txt => 03e.txt (100%) diff --git a/1.txt b/01.txt similarity index 100% rename from 1.txt rename to 01.txt diff --git a/01a.c b/01a.c new file mode 100644 index 0000000..87f4834 --- /dev/null +++ b/01a.c @@ -0,0 +1,31 @@ +#include +#include +#include + +bool read_int(int *r) +{ + char c; + *r = 0; + while (isdigit(c = getchar())) + *r = *r*10 + c-'0'; + return c != EOF; +} + +int one(int winsize) +{ + int win[winsize+1], wi = 0, increase = 0; + for (; wi 0) + increase++; + wi = (wi+1) % (winsize+1); + } + return increase; +} + +int main(void) +{ + printf("%d\n", one(1)); + return 0; +} diff --git a/01.c b/01b.c similarity index 91% rename from 01.c rename to 01b.c index b667be8..23e0821 100644 --- a/01.c +++ b/01b.c @@ -26,9 +26,6 @@ int one(int winsize) int main(void) { - //For a - //printf("%d\n", one(1)); - //For b printf("%d\n", one(3)); return 0; } diff --git a/1e.txt b/01e.txt similarity index 100% rename from 1e.txt rename to 01e.txt diff --git a/2.txt b/02.txt similarity index 100% rename from 2.txt rename to 02.txt diff --git a/02b.l b/02b.l index 92ed694..9f43954 100644 --- a/02b.l +++ b/02b.l @@ -20,6 +20,6 @@ down\ [0-9] aim += atoi(yytext+sizeof("down")); int main (void) { yylex(); - printf("x: %d, z: %d, x*z: %d\n", x, z, x*z); + printf("%d\n", x*z); return 0; } diff --git a/2e.txt b/02e.txt similarity index 100% rename from 2e.txt rename to 02e.txt diff --git a/3.txt b/03.txt similarity index 100% rename from 3.txt rename to 03.txt diff --git a/3e.txt b/03e.txt similarity index 100% rename from 3e.txt rename to 03e.txt diff --git a/Makefile b/Makefile index 2f07760..9b65f6b 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,17 @@ CFLAGS:=-Wall -Wextra -O3 LFLAGS:=-f -BINARIES:=01 02a 02b 03a 03b +BINARIES:=$(foreach num,$(shell seq -f '%02.0f' 1 3),$(num)a $(num)b) all: $(BINARIES) clean: $(RM) *.o a.out $(BINARIES) + +run: $(addprefix run_,$(BINARIES)) + +run_%a: %a + ./$< < $*.txt + +run_%b: %b + ./$< < $*.txt -- 2.20.1