day 7 simplify awk solution

inspired by elly's fennel solution
main
magical 2022-12-06 22:41:12 -08:00
parent e2a67c4b5c
commit f4be6a5be3
1 changed files with 7 additions and 20 deletions

View File

@ -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") {
cmd == "ls" && $1 != "dir" {
#print(dir "/" $2, $1)
add($1)
}
}
END {