Update script.rb

Added i and j variable to for loops, switched "array.length-1" and "array.length-2" between inner and outer loop. Changed start point of inner loop to "i+1" to eliminate unnecessary calculations