diff --git a/d07/part1.awk b/d07/part1.awk new file mode 100644 index 0000000..57483cf --- /dev/null +++ b/d07/part1.awk @@ -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 } \ No newline at end of file diff --git a/d07/print.awk b/d07/print.awk new file mode 100644 index 0000000..d8b9e1b --- /dev/null +++ b/d07/print.awk @@ -0,0 +1,47 @@ +$2 == "ls" || $1 == "dir" { next} +$2 == "cd" && $3 != ".." { + depth += 1 + l = "" + for (i=1;i", 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 +# ...