Sorting algorithms/Bogosort: Difference between revisions

added a Common Lisp solution
(added a Common Lisp solution)
Line 336:
}
}</lang>
 
=={{header|Common Lisp}}==
 
Sortedp checks that each element of a list is related by predicate to the next element of the list. I.e., (sortedp (x1 x2 ... xn) pred) is true when each of pred(x1,x2), ..., pred(xn-1,xn) is true.
 
<lang lisp>(defun shuffle (list)
(sort list #'(lambda (x y)
(declare (ignore x y))
(zerop (random 2)))))
 
(defun sortedp (list predicate)
(every predicate list (rest list)))
 
(defun bogosort (list predicate)
(do ((list list (shuffle list)))
((sortedp list predicate) list)))</lang>
 
=={{header|D}}==
Anonymous user