Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
38
Task/Knuths-algorithm-S/Phix/knuths-algorithm-s-3.phix
Normal file
38
Task/Knuths-algorithm-S/Phix/knuths-algorithm-s-3.phix
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
with javascript_semantics
|
||||
function s_of_n(integer i, sequence samples, integer item)
|
||||
samples = deep_copy(samples)
|
||||
integer n = length(samples)
|
||||
i += 1
|
||||
if i<=n then
|
||||
samples[i] = item
|
||||
elsif n/i>rnd() then
|
||||
samples[rand(n)] = item
|
||||
end if
|
||||
return {{i,samples},samples}
|
||||
end function
|
||||
|
||||
function s_of_n_creator(integer n)
|
||||
return define_lambda(s_of_n,{0,repeat(0,n)},true)
|
||||
end function
|
||||
|
||||
function test(integer n, sequence items)
|
||||
lambda l = s_of_n_creator(n)
|
||||
sequence samples
|
||||
for item in items do
|
||||
samples = call_lambda(l,item)
|
||||
end for
|
||||
return samples
|
||||
end function
|
||||
|
||||
procedure main()
|
||||
sequence items_set = tagset(9,0),
|
||||
frequencies = repeat(0,length(items_set))
|
||||
for i=1 to 100000 do
|
||||
sequence res = test(3, items_set)
|
||||
for fdx in res do
|
||||
frequencies[fdx+1] += 1
|
||||
end for
|
||||
end for
|
||||
?frequencies
|
||||
end procedure
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue