From 394df58d6da6928a6a3ebae31362342deca74b48 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 1 Dec 2021 08:56:00 +0100 Subject: Add a shell script solution --- 2021/01/Makefile | 10 ++++++---- 2021/01/README | 3 +++ 2021/01/puzzles.sh | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 2021/01/README create mode 100644 2021/01/puzzles.sh (limited to '2021') 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 }' -- cgit v1.2.3