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 } /^\$/ { cmd = $2 }
/^\$ cd/ { /^\$ cd \/$/ { depth = 0; next }
if ($3 == "/") { /^\$ cd \.\.$/ { depth -= 1; next }
depth = 0 /^\$ cd/ { cwd[depth++] = $3; next }
} else if ($3 == "..") { /^\$ ls$/ { next }
depth -= 1
} else {
cwd[depth++] = $3
}
#print dir
next
}
/^\$ ls$/ {
next
}
function add(sz) { function add(sz) {
sizes["/"] += sz sizes["/"] += sz
@ -29,11 +18,9 @@ function add(sz) {
} }
} }
cmd == "ls" { cmd == "ls" && $1 != "dir" {
if ($1 != "dir") { #print(dir "/" $2, $1)
#print(dir "/" $2, $1) add($1)
add($1)
}
} }
END { END {