Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
s_of_n_creator = (n) ->
|
||||
arr = []
|
||||
cnt = 0
|
||||
(elem) ->
|
||||
cnt += 1
|
||||
if cnt <= n
|
||||
arr.push elem
|
||||
else
|
||||
pos = Math.floor(Math.random() * cnt)
|
||||
if pos < n
|
||||
arr[pos] = elem
|
||||
arr.sort()
|
||||
|
||||
sample_size = 3
|
||||
range = [0..9]
|
||||
num_trials = 100000
|
||||
|
||||
counts = {}
|
||||
|
||||
for digit in range
|
||||
counts[digit] = 0
|
||||
|
||||
for i in [1..num_trials]
|
||||
s_of_n = s_of_n_creator(sample_size)
|
||||
for digit in range
|
||||
sample = s_of_n(digit)
|
||||
for digit in sample
|
||||
counts[digit] += 1
|
||||
|
||||
for digit in range
|
||||
console.log digit, counts[digit]
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
> coffee knuth_sample.coffee
|
||||
0 29899
|
||||
1 29841
|
||||
2 29930
|
||||
3 30058
|
||||
4 29932
|
||||
5 29948
|
||||
6 30047
|
||||
7 30114
|
||||
8 29976
|
||||
9 30255
|
||||
Loading…
Add table
Add a link
Reference in a new issue