aboutsummaryrefslogtreecommitdiff
path: root/2021
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-12-01 08:56:00 +0100
committerThomas Voss <thomasvoss@live.com> 2021-12-01 08:56:00 +0100
commit394df58d6da6928a6a3ebae31362342deca74b48 (patch)
tree9d9130761da691dbe923b5f1400bec69e087c223 /2021
parent32fe21038a75a3f6da911c92247e422885cb521b (diff)
Add a shell script solution
Diffstat (limited to '2021')
-rw-r--r--2021/01/Makefile10
-rw-r--r--2021/01/README3
-rw-r--r--2021/01/puzzles.sh3
3 files changed, 12 insertions, 4 deletions
diff --git a/2021/01/Makefile b/2021/01/Makefile
index 9f0c9fb..d6b3c62 100644
--- a/2021/01/Makefile
+++ b/2021/01/Makefile
@@ -1,8 +1,10 @@
all:
- sed '/# START PART 2/,/# END PART 2/d' puzzles.py >puzzle-1.py
- sed '/# START PART 1/,/# END PART 1/d' puzzles.py >puzzle-2.py
- chmod +x puzzle-[12].py
+ for ext in py sh; do \
+ m4 -D DELTA=1 puzzles.$$ext >puzzle-1.$$ext; \
+ m4 -D DELTA=3 puzzles.$$ext >puzzle-2.$$ext; \
+ done
+ chmod +x puzzle-[12].{py,sh}
.PHONY: clean
clean:
- rm -f puzzle-[12].py
+ rm -f puzzle-[12].{py,sh}
diff --git a/2021/01/README b/2021/01/README
new file mode 100644
index 0000000..8f9110a
--- /dev/null
+++ b/2021/01/README
@@ -0,0 +1,3 @@
+Originally written in Python because it's an easy language and I was speedcoding this at 6:00. In
+hindsight this is a good shell script problem, so I wrote it again in that (it would have been my
+goto language if I didn't have a python setup waiting for the clock to hit 6:00).
diff --git a/2021/01/puzzles.sh b/2021/01/puzzles.sh
new file mode 100644
index 0000000..9cf8043
--- /dev/null
+++ b/2021/01/puzzles.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env sh
+
+paste -s input | awk '{ for (i = 1; i < NF; i++) c += $i < $(i + DELTA) } END { print c }'