Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Knuth-shuffle/AutoHotkey/knuth-shuffle-1.ahk
Normal file
13
Task/Knuth-shuffle/AutoHotkey/knuth-shuffle-1.ahk
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
MsgBox % shuffle("1,2,3,4,5,6,7,8,9")
|
||||
MsgBox % shuffle("1,2,3,4,5,6,7,8,9")
|
||||
|
||||
shuffle(list) { ; shuffle comma separated list, converted to array
|
||||
StringSplit a, list, `, ; make array (length = a0)
|
||||
Loop % a0-1 {
|
||||
Random i, A_Index, a0 ; swap item 1,2... with a random item to the right of it
|
||||
t := a%i%, a%i% := a%A_Index%, a%A_Index% := t
|
||||
}
|
||||
Loop % a0 ; construct string from sorted array
|
||||
s .= "," . a%A_Index%
|
||||
Return SubStr(s,2) ; drop leading comma
|
||||
}
|
||||
17
Task/Knuth-shuffle/AutoHotkey/knuth-shuffle-2.ahk
Normal file
17
Task/Knuth-shuffle/AutoHotkey/knuth-shuffle-2.ahk
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
toShuffle:=[1,2,3,4,5,6]
|
||||
shuffled:=shuffle(toShuffle)
|
||||
;p(toShuffle) ;because it modifies the original array
|
||||
;or
|
||||
;p(shuffled)
|
||||
shuffle(a)
|
||||
{
|
||||
i := a.Length()
|
||||
loop % i-1 {
|
||||
Random, j,1,% i
|
||||
x := a[i]
|
||||
a[i] := a[j]
|
||||
a[j] := x
|
||||
i--
|
||||
}
|
||||
return a
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue