From cf72f8d6a24dae3794543278a0eec140ace2b615 Mon Sep 17 00:00:00 2001 From: Dory Date: Thu, 4 Dec 2025 14:49:56 -0800 Subject: [PATCH] d1p1 --- d01/d1p1.sed | 121 ++ d01/input.txt | 4780 +++++++++++++++++++++++++++++++++++++++++++++++++ d01/test.txt | 11 + 3 files changed, 4912 insertions(+) create mode 100755 d01/d1p1.sed create mode 100644 d01/input.txt create mode 100644 d01/test.txt diff --git a/d01/d1p1.sed b/d01/d1p1.sed new file mode 100755 index 0000000..6a744c5 --- /dev/null +++ b/d01/d1p1.sed @@ -0,0 +1,121 @@ +#!/usr/bin/sed -nEf + +x; s/^$/bbbbb/; x # put "50/0" into the hold buffer + +:line +# = # print current line for debug + +# we reached the end of input; print out the number of zeroes we've seen +/^$/ { + s//answer: /; p + g + s/[^-]//g + s/-/a/g + s/aaaaaaaaaa/b/g + s/bbbbbbbbbb/c/g + s/cccccccccc/d/g + + s/d([^d]|$)/1%\1/ + s/c([^c]|$)/1%\1/ + s/b([^b]|$)/1%\1/ + s/a([^a]|$)/1%\1/ + + s/a1/2/; s/a2/3/; s/a3/4/; s/a4/5/; s/a5/6/; s/a6/7/; s/a7/8/; s/a8/9/ + s/b1/2/; s/b2/3/; s/b3/4/; s/b4/5/; s/b5/6/; s/b6/7/; s/b7/8/; s/b8/9/ + s/c1/2/; s/c2/3/; s/c3/4/; s/c4/5/; s/c5/6/; s/c6/7/; s/c7/8/; s/c8/9/ + s/d1/2/; s/d2/3/; s/d3/4/; s/d4/5/; s/d5/6/; s/d6/7/; s/d7/8/; s/d8/9/ + s/%//g + + p +} + +# convert L/R to to save letters for digits +s/^R/>/ +s/^L// { + # strip the L|R + s/.(.*)/\1/ + + # append the content of hold buffer to pattern buffer + G; s/\n//g + + # sort the characters + s/([^a]*)(a*)([^a]*)(a+)([^a]*)/\2\4\1\3\5/g + s/([^b]*)(b*)([^a]*)(b+)([^b]*)/\2\4\1\3\5/g + + # add & carry + s/aaaaaaaaaa/b/g + s/bbbbbbbbbb//g # 100 overflows to 0 + h + #p # debug print +} + +# counter-clockwise rotation case +/^