YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
44
Task/Knuths-algorithm-S/Phix/knuths-algorithm-s-1.phix
Normal file
44
Task/Knuths-algorithm-S/Phix/knuths-algorithm-s-1.phix
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
enum RID, I, SAMPLE
|
||||
|
||||
function s_of_n(sequence env, integer item)
|
||||
integer i = env[I] + 1,
|
||||
n = length(env[SAMPLE])
|
||||
env[I] = i
|
||||
if i<=n then
|
||||
env[SAMPLE][i] = item
|
||||
elsif n/i>rnd() then
|
||||
env[SAMPLE][rand(n)] = item
|
||||
end if
|
||||
return env
|
||||
end function
|
||||
|
||||
function s_of_n_creator(int n)
|
||||
return {routine_id("s_of_n"),0,repeat(0,n)}
|
||||
end function
|
||||
|
||||
function invoke(sequence env, args)
|
||||
env = call_func(env[RID],prepend(args,env))
|
||||
return env
|
||||
end function
|
||||
|
||||
function test(integer n, sequence items)
|
||||
sequence env = s_of_n_creator(n)
|
||||
for i=1 to length(items) do
|
||||
-- env = s_of_n(env,items[i])
|
||||
env = invoke(env, {items[i]})
|
||||
end for
|
||||
return env[SAMPLE]
|
||||
end function
|
||||
|
||||
procedure main()
|
||||
sequence items_set = tagset(9,0)
|
||||
sequence frequencies = repeat(0,length(items_set))
|
||||
for i=1 to 100000 do
|
||||
sequence res = test(3, items_set)
|
||||
for j=1 to length(res) do
|
||||
frequencies[res[j]+1] += 1
|
||||
end for
|
||||
end for
|
||||
?frequencies
|
||||
end procedure
|
||||
main()
|
||||
9
Task/Knuths-algorithm-S/Phix/knuths-algorithm-s-2.phix
Normal file
9
Task/Knuths-algorithm-S/Phix/knuths-algorithm-s-2.phix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
enum RID, I, SAMPLE, CLOSURE_LEN=$
|
||||
...
|
||||
function s_of_n_creator(int n)
|
||||
sequence closure = repeat(0,CLOSURE_LEN)
|
||||
closure[RID] = routine_id("s_of_n")
|
||||
closure[I] = 0
|
||||
closure[SAMPLE] = repeat(0,n)
|
||||
return closure
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue