Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Knuth-shuffle/PureBasic/knuth-shuffle.basic
Normal file
32
Task/Knuth-shuffle/PureBasic/knuth-shuffle.basic
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
EnableExplicit
|
||||
|
||||
Procedure KnuthShuffle(Array a(1))
|
||||
Protected i, last = ArraySize(a())
|
||||
|
||||
For i = last To 1 Step -1
|
||||
Swap a(i), a(Random(i))
|
||||
Next
|
||||
EndProcedure
|
||||
|
||||
Procedure.s ArrayToString(Array a(1))
|
||||
Protected ret$, i, last = ArraySize(a())
|
||||
|
||||
ret$ = Str(a(0))
|
||||
For i = 1 To last
|
||||
ret$ + "," + Str(a(i))
|
||||
Next
|
||||
ProcedureReturn ret$
|
||||
EndProcedure
|
||||
|
||||
|
||||
#NumElements = 10
|
||||
|
||||
Dim a(#NumElements-1)
|
||||
Define i
|
||||
|
||||
For i = 0 To #NumElements-1
|
||||
a(i) = i
|
||||
Next
|
||||
|
||||
KnuthShuffle(a())
|
||||
Debug "shuffled: " + ArrayToString(a())
|
||||
Loading…
Add table
Add a link
Reference in a new issue