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