From: Peter Date: 2003-12-04T19:46:21+09:00 Subject: Re: sorting > 0.upto(n-2) |i| > ii = i+1 > ii.upto(n-1) |j| > if ( x[i] <=> x[j] ) == 1 > swap(x[i],x[j]) > end > end > end Actually you should insert a do before |i| and |j|: 0.upto(n-2) do |i| ii = i+1 ii.upto(n-1) do |j| if ( x[i] <=> x[j] ) == 1 x[i],x[j]=x[j],x[i] end end end And this version works on a few random samples (I didn't change the algorithm, so your thinking was correct :-) def sort(x) n = x.length 0.upto(n-2) do |i| ii = i+1 ii.upto(n-1) do |j| if ( x[i] <=> x[j] ) == 1 x[i],x[j]=x[j],x[i] end end end end Peter