aboutsummaryrefslogtreecommitdiff
path: root/2021/10/puzzle-2.sed
diff options
context:
space:
mode:
Diffstat (limited to '2021/10/puzzle-2.sed')
-rw-r--r--2021/10/puzzle-2.sed18
1 files changed, 18 insertions, 0 deletions
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/