diff --git a/07/01.sh b/07/01.sh index 9ae2987..8b6d178 100755 --- a/07/01.sh +++ b/07/01.sh @@ -52,5 +52,3 @@ for i in ${!tree[@]}; do done echo $sum - -echo ${tree[/jqfwd/hqb/vbzr/gbh/]} diff --git a/07/02.sh b/07/02.sh new file mode 100755 index 0000000..bd060ee --- /dev/null +++ b/07/02.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +pwd='' +declare -A tree + +out="$(while read line; do + IFS=' ' + if [[ "$line" == '$'* ]]; then + if [[ "$line" == *'cd'* ]]; then + fsd=($line) + if [[ ${fsd[2]} == '..' ]]; then + pwd="$(sed -E 's/\/[a-z]*$//' <<< "$pwd")" + else + pwd="$pwd/${fsd[2]}" + fi + fi + else + if [[ "$line" != "dir"* ]]; then + asd=($line) + echo "$pwd/${asd[1]} ${asd[0]}" + fi + fi +done < /tmp/07 | sed 's@//@/@g;s@//@/@g')" + +last=0 +while read line; do + item=${line/ */} + value=${line/* /} + + depth=$(($(echo "$line" | grep -o '/' | wc -l)+1)) + + IFS='/' + for (( i=1; i<$depth; i++ )); do + owo=($item) + cur=$(sed 's@ @/@g;s@$@/@' <<< "${owo[@]:0:$i}") + tree[$cur]=$((${tree[$cur]}+value)) + echo "adding from $line to $cur" + done + unset IFS + +# tree[$item]=$((${tree[$item]}+$value)) + +done <<< "$out" + +#declare -p tree +sum=0 +#for i in ${!tree[@]}; do +# y=$(grep -o '/' <<< "$i" | wc -l) +# if [[ "$y" == 2 ]]; then +# echo "${tree[$i]} $i" +# sum=$((sum+${tree[$i]})) +# fi +#done +#echo $sum + +free=$((70000000-${tree[/]})) + + +echo "free: $free" +for i in ${!tree[@]}; do + if [[ $((free+${tree[$i]})) -ge 30000000 ]]; then + echo "${tree[$i]}" + fi +done | sort -n | head -n1 + diff --git a/07/README.md b/07/README.md index fa56f31..f5fb758 100644 --- a/07/README.md +++ b/07/README.md @@ -1,6 +1,6 @@ # day 07 (oops, only 09!) -# part 1 +## part 1 UwU finally something **fun**! @@ -19,3 +19,15 @@ i hate how I handled half of the code as a subshell, but I don't care enough about it to rewrite it now Well! onto part 2... + +## part 2 + +Why the hecc did the 1st part deliberately instruct the programmer +to count directories multiple times, and the 2nd part went "well, +actually no, we want a proper size, not an imaginary size"??? + +thankfully, I have decided to write the parser code separate from +the summing code, so I could just easily throw the 2nd part out +while keeping the 1st part. + +Anyways! that was probably the most fun chall here yet! Neatâ„¢!