Last active
December 14, 2021 20:17
-
-
Save laserbat/5e20532f5d42a879fa986c0ae2774527 to your computer and use it in GitHub Desktop.
2021 AOC in sed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sed -Enf | |
# Note: this code is intended for GNU sed, other implementations of sed might have issues running it. | |
# | |
# Usage: | |
# $ ./day_1.sed < ./input.txt | |
G | |
s/\n/;/m | |
h | |
s/[0-9]/u/g | |
G | |
s/\n/#/m | |
s/;[^;]*$/;/ | |
s/^(u+)u+;\1;.*/&a/ | |
s/^(u+);\1;.*#(\w*)(\w)\w*;\2(\w).*/&a\3\4/ | |
s/^(u+)u+;u+;u+;\1;.*/&b/ | |
s/^(u+);u+;u+;\1;.*#(\w*)(\w)\w*;\w+;\w+;\2(\w).*/&b\3\4/ | |
s/[ab](99|8[89]|7[7-9]|6[6-9]|5[5-9]|4[4-9]|3[3-9]|2[2-9]|1[^0]|0.)//g | |
s/[^ab]//g | |
G | |
s/^(a?)(b?)\n(\w*;\w*;?\w*;?)[^#]*(#(\w*) (\w*)|$)/\3#\5\1 \6\2/m | |
s/b/a/ | |
:a | |
s/9a/a0/g | |
ta | |
s/(#| )a/\11/g | |
s/8a/9/g | |
s/7a/8/g | |
s/6a/7/g | |
s/5a/6/g | |
s/4a/5/g | |
s/3a/4/g | |
s/2a/3/g | |
s/1a/2/g | |
s/0a/1/g | |
h | |
$s/[^#]*#//p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment