Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Knuth-shuffle/Ol/knuth-shuffle-1.ol
Normal file
15
Task/Knuth-shuffle/Ol/knuth-shuffle-1.ol
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
(define (shuffle tp)
|
||||
(let ((items (vm:cast tp (type tp)))) ; make a copy
|
||||
(for-each (lambda (i)
|
||||
(let ((a (ref items i))
|
||||
(j (+ 1 (rand! i))))
|
||||
(set-ref! items i (ref items j))
|
||||
(set-ref! items j a)))
|
||||
(reverse (iota (size items) 1)))
|
||||
items))
|
||||
|
||||
(define (list-shuffle tp)
|
||||
(map (lambda (i)
|
||||
(list-ref tp i))
|
||||
(tuple->list
|
||||
(shuffle (list->tuple (iota (length tp)))))))
|
||||
7
Task/Knuth-shuffle/Ol/knuth-shuffle-2.ol
Normal file
7
Task/Knuth-shuffle/Ol/knuth-shuffle-2.ol
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(define items (tuple 1 2 3 4 5 6 7 8 9))
|
||||
(print "tuple before: " items)
|
||||
(print "tuple after: " (shuffle items))
|
||||
|
||||
(define items (list 1 2 3 4 5 6 7 8 9))
|
||||
(print "list before: " items)
|
||||
(print "list after: " (list-shuffle items))
|
||||
Loading…
Add table
Add a link
Reference in a new issue