day 5 awk add some comments
parent
29b20e27fc
commit
bc646722df
|
@ -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--) {
|
||||||
|
|
Loading…
Reference in New Issue