Sorting algorithms/Bogosort: Difference between revisions

→‎{{header|Octave}}: Deleted because this implementation is incorrect (randomization does not provide a permutation); moreover it is very inefficient, because no vectorization is used; And the Matlab version works fine with Octave (v3.4 at least)
(→‎{{header|MATLAB}}: works fine with Octave, too.)
(→‎{{header|Octave}}: Deleted because this implementation is incorrect (randomization does not provide a permutation); moreover it is very inefficient, because no vectorization is used; And the Matlab version works fine with Octave (v3.4 at least))
Line 1,095:
- : int list = [1; 2; 4; 5; 7; 12; 18; 23]
</pre>
 
=={{header|Octave}}==
<lang octave>function y = is_sorted(v)
y = true;
for i = 2:length(v)
if ( v(i-1) > v(i) )
y = false;
return
endif
endfor
endfunction
 
function r = shuffle(v)
l = length(v);
for i = 1:l
t = v(i);
r = unidrnd(l);
v(i) = v(r);
v(r) = t;
endfor
r = v;
endfunction
 
function s = bogosort(v)
while( !is_sorted(v) )
v = shuffle(v);
endwhile
s = v;
endfunction</lang>
 
<lang octave>n = [ 1, 10, 9, 7, 3, 0 ];
disp(bogosort(n));</lang>
 
=={{header|Oz}}==
Anonymous user