day 7, "at most" is "less than", not "more than"!
This commit is contained in:
parent
277be4d57c
commit
37f0f25dec
|
@ -0,0 +1,16 @@
|
|||
BEGIN { LIMIT=100*1000 }
|
||||
$2 == "ls" || $1 == "dir" { next}
|
||||
$2 == "cd" && $3 == ".." {
|
||||
if (S[depth]<=LIMIT) {
|
||||
R+=S[depth]
|
||||
}
|
||||
S[depth]=0
|
||||
depth -= 1
|
||||
}
|
||||
$2 == "cd" && $3 != ".." { depth += 1; P[depth]=$3; }
|
||||
NF == 2 {
|
||||
for (i=1;i<=depth;i++) {
|
||||
S[i]+=$1
|
||||
}
|
||||
}
|
||||
END { print R }
|
|
@ -0,0 +1,47 @@
|
|||
$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
|
||||
# ...
|
Loading…
Reference in New Issue