From ce446be29621d6afdd5b23338833478b1a3c013a Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Thu, 1 Dec 2022 10:48:09 +0100 Subject: [PATCH] cleanup code --- 2022/day01/aoc.bash | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/2022/day01/aoc.bash b/2022/day01/aoc.bash index a8d474c..fb51e89 100755 --- a/2022/day01/aoc.bash +++ b/2022/day01/aoc.bash @@ -15,7 +15,7 @@ declare -a total declare max=0 -declare -i res +declare -i res=0 parse() { local -i elf=0 @@ -36,18 +36,15 @@ part1() { part2() { local -i i elf newbest - res=0 + for ((i=0; i<3; ++i)); do newbest=0 for ((elf=0; elf<${#total[@]}; ++elf)); do - if (( total[elf] > total[newbest] )); then - newbest=$elf - fi + (( total[elf] > total[newbest] )) && newbest=$elf done (( res+=total[newbest] )) unset "total[$newbest]" # remove current max total=("${total[@]}") # pack array - #printf "%d: %s\n" "$i" "${total[*]}" done }