day 5 awk add some comments

main
magical 2022-12-07 12:07:43 -08:00
parent 29b20e27fc
commit bc646722df
1 changed files with 6 additions and 4 deletions

View File

@ -1,15 +1,17 @@
# run me with awk -f sol.awk < input
/\[/ {
gsub("^ ", "[ ]")
gsub(" {4}", " [ ]")
gsub("^\\[|\\] \\[|\\]$", "")
/\[/ { # " [A] [B] [C] "
gsub("^ ", "[ ]") # "[ ] [A] [B] [C] "
gsub(" {4}", " [ ]") # "[ ] [A] [ ] [B] [C] [ ]"
gsub("^\\[|\\] \\[|\\]$", "") # " A BC "
lines[nlines++] = $0
if (nstacks < length())
nstacks = length()
}
/^$/ {
# transpose lines[j][i] -> stack[i][-j]
# and strip trailing spaces
for (i = 1; i <= nstacks; i++) {
s = ""
for (j = nlines-1; j >= 0; j--) {