cleanup code

This commit is contained in:
2022-12-01 10:48:09 +01:00
parent a8cab0c7c3
commit ce446be296

View File

@@ -15,7 +15,7 @@
declare -a total declare -a total
declare max=0 declare max=0
declare -i res declare -i res=0
parse() { parse() {
local -i elf=0 local -i elf=0
@@ -36,18 +36,15 @@ part1() {
part2() { part2() {
local -i i elf newbest local -i i elf newbest
res=0
for ((i=0; i<3; ++i)); do for ((i=0; i<3; ++i)); do
newbest=0 newbest=0
for ((elf=0; elf<${#total[@]}; ++elf)); do for ((elf=0; elf<${#total[@]}; ++elf)); do
if (( total[elf] > total[newbest] )); then (( total[elf] > total[newbest] )) && newbest=$elf
newbest=$elf
fi
done done
(( res+=total[newbest] )) (( res+=total[newbest] ))
unset "total[$newbest]" # remove current max unset "total[$newbest]" # remove current max
total=("${total[@]}") # pack array total=("${total[@]}") # pack array
#printf "%d: %s\n" "$i" "${total[*]}"
done done
} }