Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Knuth-shuffle/Oz/knuth-shuffle.oz
Normal file
19
Task/Knuth-shuffle/Oz/knuth-shuffle.oz
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
declare
|
||||
proc {Shuffle Arr}
|
||||
Low = {Array.low Arr}
|
||||
High = {Array.high Arr}
|
||||
in
|
||||
for I in High..Low;~1 do
|
||||
J = Low + {OS.rand} mod (I - Low + 1)
|
||||
OldI = Arr.I
|
||||
in
|
||||
Arr.I := Arr.J
|
||||
Arr.J := OldI
|
||||
end
|
||||
end
|
||||
|
||||
X = {Tuple.toArray unit(0 1 2 3 4 5 6 7 8 9)}
|
||||
in
|
||||
{Show {Array.toRecord unit X}}
|
||||
{Shuffle X}
|
||||
{Show {Array.toRecord unit X}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue