Ok @CvxFous, thank you but with this I can't get 100%, the problem may come from the second loop, after having sort the array, I did this to find the smallest :
for (( i=2; i<N; i++));do
j=$(( $i-1 ))
if [ $smallest -eq -1 ] || [ $diff -lt $smallest ]; then
if [ $smallest -eq 0 ]; then
What do you think ? This not optimized enough ?