clean up bash solution a bit more

This commit is contained in:
Patrick Michl 2022-12-01 08:27:33 +01:00
parent 14b097c61d
commit 0b28781160
No known key found for this signature in database
GPG Key ID: BFE0ACEE21CD5EB0

View File

@ -5,13 +5,13 @@ INPUT="$(<data/day_1.txt)"
qsort() {
read -ra arr <<< "$@"
[[ "${#arr[@]}" == 0 ]] && echo "" && return
((${#arr[@]} == 0)) && echo && return
local smaller=() bigger=() pivot="${arr[0]}" res=()
for i in "${arr[@]}"; do
if [[ "$i" -lt "$pivot" ]]; then
if ((i < pivot)); then
smaller+=("$i")
elif [[ "$i" -gt "$pivot" ]]; then
elif ((i > pivot)); then
bigger+=("$i")
fi
done
@ -37,6 +37,7 @@ p1() {
read -ra cals <<< "$(cals_per_elf "$1")"
echo "${cals[@]: -1}"
}
p2() {
read -ra cals <<< "$(cals_per_elf "$1")"
local result=0