Talk:Best shuffle: Difference between revisions

→‎Common Lisp: new section
(→‎Common Lisp: new section)
Line 160:
 
I have updated the code on the task page to remove the while loop. --[[User:Paddy3118|Paddy3118]] 08:49, 22 May 2011 (UTC)
 
== Common Lisp ==
 
the task description says "A shuffle that produces a randomized result is to be preferred." so i don't see how this is compared to general permutation tasks which seem to ask for all possible permutations instead of one random permutation.
 
i posted a function for generating a random permutation as per the task description, and am still working on comparing the results.
 
maybe it is better to save the incomplete solution here and move it to the main page when it is ready.
 
:this alternative version is based on a [http://blog.viridian-project.de/2008/04/06/sequence-shuffling-revisited/ discussion here]
<lang lisp>(defun better-shuffle (seq)
(let ((tagged (mapcar (lambda (x) (cons (random 1.0) x)) (loop for char across seq collect char))))
(coerce (mapcar 'cdr (sort tagged #'> :key 'car)) 'string)))
 
(map 'list 'shuffle '("abracadabra" "seesaw" "elk" "grrrrrr" "up" "a"))
("rbcarabdaaa" "wassee" "ekl" "rrrrrgr" "up" "a")</lang>
:--[[User:EMBee|eMBee]] 07:21, 14 October 2011 (UTC)
Anonymous user