RosettaCodeData/Task/Knuth-shuffle/Joy/knuth-shuffle-1.joy
2023-07-01 13:44:08 -04:00

12 lines
370 B
Text

DEFINE knuth-shuffle ==
(* Take the size of the array (without destroying it) *)
dup dup size
(* Generate a list of as many random numbers *)
[rand] [rem] enconcat map
(* Zip the two lists *)
swap zip
(* Sort according to the new index number *)
[small] [] [uncons unswonsd [first >] split [swons] dip2]
[enconcat] binrec
(* Delete the new index number *)
[second] map.