aoc2022/d07/print.awk

48 lines
867 B
Awk

$2 == "ls" || $1 == "dir" { next}
$2 == "cd" && $3 != ".." {
depth += 1
l = ""
for (i=1;i<depth;i++) {
l = l "___ "
}
print l $3 "/"
}
NF == 2 {
l = ""
for (i=1;i<=depth;i++) {
S[i]+=$1
l = l "___ "
}
print l $2, "(" $1 ")"
}
$2 == "cd" && $3 == ".." {
l = ""
for (i=1;i<depth;i++) {
l = l "___ "
}
print l "=>", S[depth]
S[depth]=0
depth -= 1
}
# part 1
# awk -f print.awk input | grep -F '=>' | awk 'NF>2 && $(NF)>(100*1000)' | awk '{ print $NF }' | sum0
# part 2
# TOTAL 70'000'000
# UPDATE 30'000'000
# ROOT 43'837'783
# FREE 26'162'217
# NEED 3'837'783
# list all sizes
# awk -f print.awk input | grep -F '=>' | awk 'NF>2 && $(NF)>(100*1000)' | awk '{ print $NF }' | sort -n
# find number at the bottom of the list that is >=NEED
# ...
# 2882941
# 3572786
# 3718312 <= too low
# 4183246 <= this one
# 5406295
# 5928595
# ...