clean up bash solution a bit more
This commit is contained in:
parent
14b097c61d
commit
0b28781160
11
src/day_1.sh
11
src/day_1.sh
@ -5,14 +5,14 @@ INPUT="$(<data/day_1.txt)"
|
|||||||
|
|
||||||
qsort() {
|
qsort() {
|
||||||
read -ra arr <<< "$@"
|
read -ra arr <<< "$@"
|
||||||
[[ "${#arr[@]}" == 0 ]] && echo "" && return
|
((${#arr[@]} == 0)) && echo && return
|
||||||
local smaller=() bigger=() pivot="${arr[0]}" res=()
|
local smaller=() bigger=() pivot="${arr[0]}" res=()
|
||||||
|
|
||||||
for i in "${arr[@]}"; do
|
for i in "${arr[@]}"; do
|
||||||
if [[ "$i" -lt "$pivot" ]]; then
|
if ((i < pivot)); then
|
||||||
smaller+=("$i")
|
smaller+=("$i")
|
||||||
elif [[ "$i" -gt "$pivot" ]]; then
|
elif ((i > pivot)); then
|
||||||
bigger+=("$i")
|
bigger+=("$i")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -37,6 +37,7 @@ p1() {
|
|||||||
read -ra cals <<< "$(cals_per_elf "$1")"
|
read -ra cals <<< "$(cals_per_elf "$1")"
|
||||||
echo "${cals[@]: -1}"
|
echo "${cals[@]: -1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
p2() {
|
p2() {
|
||||||
read -ra cals <<< "$(cals_per_elf "$1")"
|
read -ra cals <<< "$(cals_per_elf "$1")"
|
||||||
local result=0
|
local result=0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user