rename, cleanup, improve makefile
authorMart Lubbers <mart@martlubbers.net>
Fri, 3 Dec 2021 09:12:21 +0000 (10:12 +0100)
committerMart Lubbers <mart@martlubbers.net>
Fri, 3 Dec 2021 09:12:21 +0000 (10:12 +0100)
01.txt [moved from 1.txt with 100% similarity]
01a.c [new file with mode: 0644]
01b.c [moved from 01.c with 91% similarity]
01e.txt [moved from 1e.txt with 100% similarity]
02.txt [moved from 2.txt with 100% similarity]
02b.l
02e.txt [moved from 2e.txt with 100% similarity]
03.txt [moved from 3.txt with 100% similarity]
03e.txt [moved from 3e.txt with 100% similarity]
Makefile

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 (file)
index 0000000..87f4834
--- /dev/null
+++ b/01a.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include <ctype.h>
+
+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<winsize; wi++)
+               read_int(&win[wi]);
+       while (read_int(&win[wi])) {
+               if (win[wi] - win[(wi+winsize+2) % (winsize+1)] > 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 (file)
--- 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 (file)
--- 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
index 2f07760..9b65f6b 100644 (file)
--- 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