Bash Triangle
triangle() {
local -n _a="$1"
local -a _sorted=($(printf '%s\n' "${_a[@]}" | sort -n))
local _c=${#_sorted[@]}
if (( _c < 3 )); then
echo 0
return
fi
local _i
for ((_i = 0; _i < _c - 2; _i++)); do
if (( _sorted[_i] > 0 && _sorted[_i] > _sorted[_i+2] - _sorted[_i+1] )); then
echo 1
return
fi
done
echo 0
}
This sorts the values and checks nearby triples, because a valid triangle only needs one local match after sorting.