cleanup code
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user