diff --git a/day07/sol.awk b/day07/sol.awk index accdf47..8469ac0 100644 --- a/day07/sol.awk +++ b/day07/sol.awk @@ -4,21 +4,10 @@ BEGIN { depth = 0 } /^\$/ { cmd = $2 } -/^\$ cd/ { - if ($3 == "/") { - depth = 0 - } else if ($3 == "..") { - depth -= 1 - } else { - cwd[depth++] = $3 - } - #print dir - next -} - -/^\$ ls$/ { - next -} +/^\$ cd \/$/ { depth = 0; next } +/^\$ cd \.\.$/ { depth -= 1; next } +/^\$ cd/ { cwd[depth++] = $3; next } +/^\$ ls$/ { next } function add(sz) { sizes["/"] += sz @@ -29,11 +18,9 @@ function add(sz) { } } -cmd == "ls" { - if ($1 != "dir") { - #print(dir "/" $2, $1) - add($1) - } +cmd == "ls" && $1 != "dir" { + #print(dir "/" $2, $1) + add($1) } END {