Sorting algorithms/Bogosort: Difference between revisions

Content added Content deleted
(Added XPL0)
No edit summary
Line 1,466: Line 1,466:
n <- c(1, 10, 9, 7, 3, 0)
n <- c(1, 10, 9, 7, 3, 0)
print(bogosort(n))</lang>
print(bogosort(n))</lang>

=={{header|Racket}}==

Only the first line is needed to implement the bogo sort, the rest
is unit tests and an example.

<lang racket>
#lang racket
(define (bogo-sort l) (if (apply <= l) l (bogo-sort (shuffle l))))

(require rackunit)
(check-equal? (bogo-sort '(6 5 4 3 2 1)) '(1 2 3 4 5 6))
(check-equal? (bogo-sort (shuffle '(1 1 1 2 2 2))) '(1 1 1 2 2 2))

(let ((unsorted (for/list ((i 10)) (random 1000))))
(displayln unsorted)
(displayln (bogo-sort unsorted)))
</lang>

Output (chances are you won't get quite this!):
<pre>
(703 931 12 713 894 232 778 86 700 26)
(12 26 86 232 700 703 713 778 894 931)
</pre>


=={{header|REXX}}==
=={{header|REXX}}==