From 659cf726b146fcf8375c3629a4732bdd96182c4d Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Thu, 2 Dec 2021 10:34:26 -0500 Subject: [PATCH] layout: Remove intermediate c/py directories It was a bit annoying to traverse 3 levels just to get to the solutions! There's no real need for the distinction right now either... (filetypes say it all) --- 1/a.c | 16 ++++++++++++++++ 1/a.py | 12 ++++++++++++ 1/b.c | 26 ++++++++++++++++++++++++++ 1/b.py | 23 +++++++++++++++++++++++ 1/c/a.c | 16 ---------------- 1/c/b.c | 26 -------------------------- 1/py/a.py | 12 ------------ 1/py/b.py | 23 ----------------------- 2/a.c | 24 ++++++++++++++++++++++++ 2/a.py | 18 ++++++++++++++++++ 2/b.c | 26 ++++++++++++++++++++++++++ 2/b.py | 20 ++++++++++++++++++++ 2/c/a.c | 24 ------------------------ 2/c/b.c | 26 -------------------------- 2/py/a.py | 18 ------------------ 2/py/b.py | 20 -------------------- Makefile | 10 +++------- 17 files changed, 168 insertions(+), 172 deletions(-) create mode 100644 1/a.c create mode 100755 1/a.py create mode 100644 1/b.c create mode 100755 1/b.py delete mode 100644 1/c/a.c delete mode 100644 1/c/b.c delete mode 100755 1/py/a.py delete mode 100755 1/py/b.py create mode 100644 2/a.c create mode 100755 2/a.py create mode 100644 2/b.c create mode 100755 2/b.py delete mode 100644 2/c/a.c delete mode 100644 2/c/b.c delete mode 100755 2/py/a.py delete mode 100755 2/py/b.py diff --git a/1/a.c b/1/a.c new file mode 100644 index 0000000..f593356 --- /dev/null +++ b/1/a.c @@ -0,0 +1,16 @@ +#include +#include + +int main(void) { + int count = 0; + int curr; + int prev = 0; + while(scanf("%d\n", &curr) != EOF) { + if (prev && curr > prev) { + count++; + } + prev = curr; + } + printf("%d\n", count); + return 0; +} diff --git a/1/a.py b/1/a.py new file mode 100755 index 0000000..f0e9883 --- /dev/null +++ b/1/a.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +import sys + +prev = None +count = 0 +for l in sys.stdin: + curr = int(l.strip()) + if prev and curr > prev: + count += 1 + prev = curr + +print(count) diff --git a/1/b.c b/1/b.c new file mode 100644 index 0000000..93f6153 --- /dev/null +++ b/1/b.c @@ -0,0 +1,26 @@ +#include +#include + +int mem[] = {0, 0, 0}; +int sum() { + return mem[0] + mem[1] + mem[2]; +} + +int main(void) { + int count = 0; + int curr; + int prev = 0; + int i = 0; + while(scanf("%d\n", &curr) != EOF) { + mem[i++ % 3] = curr; + if (i > 3) { + if (prev && sum() > prev) { + count++; + } + prev = sum(); + } + i++; + } + printf("%d\n", count); + return 0; +} diff --git a/1/b.py b/1/b.py new file mode 100755 index 0000000..45dfac3 --- /dev/null +++ b/1/b.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import sys + +prev = None +mem = [] +count = 0 +i = 0 +for l in sys.stdin: + curr = int(l.strip()) + + if len(mem) < 3: + mem.append(curr) + continue + else: + mem[i % 3] = curr + i += 1 + + s = sum(mem) + if prev and s > prev: + count += 1 + prev = s + +print(count) diff --git a/1/c/a.c b/1/c/a.c deleted file mode 100644 index f593356..0000000 --- a/1/c/a.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -int main(void) { - int count = 0; - int curr; - int prev = 0; - while(scanf("%d\n", &curr) != EOF) { - if (prev && curr > prev) { - count++; - } - prev = curr; - } - printf("%d\n", count); - return 0; -} diff --git a/1/c/b.c b/1/c/b.c deleted file mode 100644 index 93f6153..0000000 --- a/1/c/b.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -int mem[] = {0, 0, 0}; -int sum() { - return mem[0] + mem[1] + mem[2]; -} - -int main(void) { - int count = 0; - int curr; - int prev = 0; - int i = 0; - while(scanf("%d\n", &curr) != EOF) { - mem[i++ % 3] = curr; - if (i > 3) { - if (prev && sum() > prev) { - count++; - } - prev = sum(); - } - i++; - } - printf("%d\n", count); - return 0; -} diff --git a/1/py/a.py b/1/py/a.py deleted file mode 100755 index f0e9883..0000000 --- a/1/py/a.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python3 -import sys - -prev = None -count = 0 -for l in sys.stdin: - curr = int(l.strip()) - if prev and curr > prev: - count += 1 - prev = curr - -print(count) diff --git a/1/py/b.py b/1/py/b.py deleted file mode 100755 index 45dfac3..0000000 --- a/1/py/b.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python3 -import sys - -prev = None -mem = [] -count = 0 -i = 0 -for l in sys.stdin: - curr = int(l.strip()) - - if len(mem) < 3: - mem.append(curr) - continue - else: - mem[i % 3] = curr - i += 1 - - s = sum(mem) - if prev and s > prev: - count += 1 - prev = s - -print(count) diff --git a/2/a.c b/2/a.c new file mode 100644 index 0000000..dcab638 --- /dev/null +++ b/2/a.c @@ -0,0 +1,24 @@ +#include +#include +#include + +int main(void) { + int depth = 0; + int pos = 0; + int val; + char comm[256]; + while(scanf("%255s %d\n", comm, &val) != EOF) { + if (!strcmp(comm, "forward")) { + pos += val; + } else if (!strcmp(comm, "up")) { + depth -= val; + } else if (!strcmp(comm, "down")) { + depth += val; + } else { + fprintf(stderr, "bad command: %s\n", comm); + exit(1); + } + } + printf("%d\n", pos * depth); + return 0; +} diff --git a/2/a.py b/2/a.py new file mode 100755 index 0000000..274ddfe --- /dev/null +++ b/2/a.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import sys + +depth = 0 +horiz = 0 + +for l in sys.stdin: + comm, val = l.split() + if comm == "down": + depth += int(val) + elif comm == "up": + depth -= int(val) + elif comm == "forward": + horiz += int(val) + else: + raise Exception(f"bad comm: {comm}") + +print(horiz * depth) diff --git a/2/b.c b/2/b.c new file mode 100644 index 0000000..3f3faee --- /dev/null +++ b/2/b.c @@ -0,0 +1,26 @@ +#include +#include +#include + +int main(void) { + int depth = 0; + int pos = 0; + int aim = 0; + int val; + char comm[256]; + while(scanf("%255s %d\n", comm, &val) != EOF) { + if (!strcmp(comm, "forward")) { + pos += val; + depth += val * aim; + } else if (!strcmp(comm, "up")) { + aim -= val; + } else if (!strcmp(comm, "down")) { + aim += val; + } else { + fprintf(stderr, "bad command: %s\n", comm); + exit(1); + } + } + printf("%d\n", pos * depth); + return 0; +} diff --git a/2/b.py b/2/b.py new file mode 100755 index 0000000..27ab67e --- /dev/null +++ b/2/b.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +import sys + +depth = 0 +horiz = 0 +aim = 0 + +for l in sys.stdin: + comm, val = l.split() + if comm == "down": + aim += int(val) + elif comm == "up": + aim -= int(val) + elif comm == "forward": + horiz += int(val) + depth += aim * int(val) + else: + raise Exception(f"bad comm: {comm}") + +print(horiz * depth) diff --git a/2/c/a.c b/2/c/a.c deleted file mode 100644 index dcab638..0000000 --- a/2/c/a.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include - -int main(void) { - int depth = 0; - int pos = 0; - int val; - char comm[256]; - while(scanf("%255s %d\n", comm, &val) != EOF) { - if (!strcmp(comm, "forward")) { - pos += val; - } else if (!strcmp(comm, "up")) { - depth -= val; - } else if (!strcmp(comm, "down")) { - depth += val; - } else { - fprintf(stderr, "bad command: %s\n", comm); - exit(1); - } - } - printf("%d\n", pos * depth); - return 0; -} diff --git a/2/c/b.c b/2/c/b.c deleted file mode 100644 index 3f3faee..0000000 --- a/2/c/b.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include - -int main(void) { - int depth = 0; - int pos = 0; - int aim = 0; - int val; - char comm[256]; - while(scanf("%255s %d\n", comm, &val) != EOF) { - if (!strcmp(comm, "forward")) { - pos += val; - depth += val * aim; - } else if (!strcmp(comm, "up")) { - aim -= val; - } else if (!strcmp(comm, "down")) { - aim += val; - } else { - fprintf(stderr, "bad command: %s\n", comm); - exit(1); - } - } - printf("%d\n", pos * depth); - return 0; -} diff --git a/2/py/a.py b/2/py/a.py deleted file mode 100755 index 274ddfe..0000000 --- a/2/py/a.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python3 -import sys - -depth = 0 -horiz = 0 - -for l in sys.stdin: - comm, val = l.split() - if comm == "down": - depth += int(val) - elif comm == "up": - depth -= int(val) - elif comm == "forward": - horiz += int(val) - else: - raise Exception(f"bad comm: {comm}") - -print(horiz * depth) diff --git a/2/py/b.py b/2/py/b.py deleted file mode 100755 index 27ab67e..0000000 --- a/2/py/b.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -import sys - -depth = 0 -horiz = 0 -aim = 0 - -for l in sys.stdin: - comm, val = l.split() - if comm == "down": - aim += int(val) - elif comm == "up": - aim -= int(val) - elif comm == "forward": - horiz += int(val) - depth += aim * int(val) - else: - raise Exception(f"bad comm: {comm}") - -print(horiz * depth) diff --git a/Makefile b/Makefile index 7bfe109..e7ea43b 100644 --- a/Makefile +++ b/Makefile @@ -11,11 +11,7 @@ CFLAGS = -g -O2 -Wall -Wpedantic -Wextra DAY = * -TARGETS = \ - 1/c/a \ - 1/c/b \ - 2/c/a \ - 2/c/b \ +TARGETS = 1/a 1/b 2/a 2/b .PHONY: build build: $(TARGETS) @@ -23,8 +19,8 @@ build: $(TARGETS) .PHONY: run run: build @for d in $(DAY)/; do \ - for sol in $${d}py/a.py $${d}c/a $${d}py/b.py $${d}c/b; do \ - [ -e $$sol ] && printf "%-10s %s\n" "$$sol:" `$$sol < $$d/input`; \ + for sol in a.py a b.py b; do \ + [ -e $$d/$$sol ] && printf "%-7s %s\n" "$${d}$$sol:" `$$d/$$sol < $$d/input`; \ done; \ done -- libgit2 1.8.1