diff --git a/day05/sol.awk b/day05/sol.awk index 7beb429..4712ece 100644 --- a/day05/sol.awk +++ b/day05/sol.awk @@ -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--) {