new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
21
Task/Knuth-shuffle/CoffeeScript/knuth-shuffle.coffee
Normal file
21
Task/Knuth-shuffle/CoffeeScript/knuth-shuffle.coffee
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
knuth_shuffle = (a) ->
|
||||
n = a.length
|
||||
while n > 1
|
||||
r = Math.floor(n * Math.random())
|
||||
n -= 1
|
||||
[a[n], a[r]] = [a[r], a[n]]
|
||||
a
|
||||
|
||||
counts =
|
||||
"1,2,3": 0
|
||||
"1,3,2": 0
|
||||
"2,1,3": 0
|
||||
"2,3,1": 0
|
||||
"3,1,2": 0
|
||||
"3,2,1": 0
|
||||
|
||||
for i in [1..100000]
|
||||
counts[knuth_shuffle([ 1, 2, 3 ]).join(",")] += 1
|
||||
|
||||
for key, val of counts
|
||||
console.log "#{key}: #{val}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue