Sorting algorithms/Bogosort: Difference between revisions

Content added Content deleted
(add E example)
Line 413: Line 413:
END PROGRAM BOGOSORT</lang>
END PROGRAM BOGOSORT</lang>

=={{header|Haskell}}==
Solution (also implicitly tracks the number of shuffles required):
<lang groovy>def bogosort = { list ->
def n = list.size()
if (n > 1) {
while ((1..<n).any{ list[it-1] > list[it] }) {
Collections.shuffle(list)
print '.'
}
}
list
}</lang>

Test Program:
<lang groovy>println bogosort([3,1,2])</lang>

Output, trial 1:
<pre>....[1, 2, 3]</pre>

Output, trial 2:
<pre>..........................[1, 2, 3]</pre>


=={{header|Haskell}}==
=={{header|Haskell}}==