diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-12-10 07:34:52 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-12-10 07:34:52 +0100 |
commit | c95723952a479ed35347cbd196dc1986be932732 (patch) | |
tree | c61f601be61861df8eb42e4e60498c3137eca3d5 /2021/10 | |
parent | f67d7c9bc53a40edbc5cc86397c0569f1c2b445f (diff) |
Add a sed/sh solution
Diffstat (limited to '2021/10')
-rw-r--r-- | 2021/10/puzzle-1.sed | 13 | ||||
-rw-r--r-- | 2021/10/puzzle-2.sed | 18 | ||||
-rwxr-xr-x | 2021/10/puzzles.sh | 4 |
3 files changed, 35 insertions, 0 deletions
diff --git a/2021/10/puzzle-1.sed b/2021/10/puzzle-1.sed new file mode 100644 index 0000000..e2e1204 --- /dev/null +++ b/2021/10/puzzle-1.sed @@ -0,0 +1,13 @@ +:top +s/()// +s/\[\]// +s/{}// +s/<>// +t top + +/[])}>]/!d + +s/^[(\[{<]*).*/3/ +s/^[(\[{<]*\].*/57/ +s/^[(\[{<]*}.*/1197/ +s/^[(\[{<]*>.*/25137/ diff --git a/2021/10/puzzle-2.sed b/2021/10/puzzle-2.sed new file mode 100644 index 0000000..887386c --- /dev/null +++ b/2021/10/puzzle-2.sed @@ -0,0 +1,18 @@ +:top +s/()// +s/\[\]// +s/{}// +s/<>// +t top + +/[])}>]/d + +:loop +s/\([(\[{<]*\)($/s = s * 5 + 1;\1/ +s/\([(\[{<]*\)\[$/s = s * 5 + 2;\1/ +s/\([(\[{<]*\){$/s = s * 5 + 3;\1/ +s/\([(\[{<]*\)<$/s = s * 5 + 4;\1/ +t loop + +s/^/s = 0;/ +s/$/s/ diff --git a/2021/10/puzzles.sh b/2021/10/puzzles.sh new file mode 100755 index 0000000..4222f7a --- /dev/null +++ b/2021/10/puzzles.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +sed -f puzzle-1.sed input | paste -sd+ | bc +sed -f puzzle-2.sed input | bc | sort -n | sed '27!d' |