Sorting algorithms/Bogosort: Difference between revisions
Content added Content deleted
(Added crystal implementation.) |
(Added Prolog) |
||
Line 2,197: | Line 2,197: | ||
$l = 7; BogoSort ( 1..$l | ForEach-Object { $Rand = New-Object Random }{ $Rand.Next( 0, $l - 1 ) } )</lang> |
$l = 7; BogoSort ( 1..$l | ForEach-Object { $Rand = New-Object Random }{ $Rand.Next( 0, $l - 1 ) } )</lang> |
||
=={{header|Prolog}}== |
|||
<lang prolog>bogo_sort(L,Rl) :- |
|||
min_list(L,Min), |
|||
repeat, |
|||
random_permutation(L,Rl), |
|||
is_sorted(Rl,Min), |
|||
!. |
|||
is_sorted([],_). |
|||
is_sorted([N|T],P) :- |
|||
N >= P, |
|||
is_sorted(T,N).</lang> |
|||
{{out}} |
|||
<pre> |
|||
?- bogo_sort( [703,931,12,713,894,232,778,86,700,26] ,Sorted). |
|||
Sorted = [12,26,86,232,700,703,713,778,894,931] . |
|||
</pre> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |