Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
43
Task/Knuths-algorithm-S/Mathematica/knuths-algorithm-s.math
Normal file
43
Task/Knuths-algorithm-S/Mathematica/knuths-algorithm-s.math
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
ClearAll[sofncreator]
|
||||
sofncreator[n_] := Module[{sample, i},
|
||||
sample = {};
|
||||
i = 0;
|
||||
Return[
|
||||
Function[{item},
|
||||
i++;
|
||||
If[i <= n,
|
||||
AppendTo[sample, item]
|
||||
,
|
||||
If[RandomInteger[{1, i}] <= n,
|
||||
sample[[RandomInteger[{1, n}]]] = item
|
||||
]
|
||||
];
|
||||
sample
|
||||
]
|
||||
]
|
||||
]
|
||||
bin = ConstantArray[0, 10];
|
||||
items = Range[10];
|
||||
sofn = sofncreator[3];
|
||||
Do[
|
||||
sample = sofn[item];
|
||||
Print[" Item: ", item, " -> sample: " , sample]
|
||||
,
|
||||
{item, items}
|
||||
]
|
||||
Do[
|
||||
sofn = sofncreator[3];
|
||||
Do[
|
||||
sample = sofn[item]
|
||||
,
|
||||
{item, items}
|
||||
];
|
||||
Do[
|
||||
bin[[s]] += 1
|
||||
,
|
||||
{s, sample}
|
||||
]
|
||||
,
|
||||
{trial, 100000}
|
||||
];
|
||||
{Range[Length[bin]], bin} // Transpose // Grid
|
||||
Loading…
Add table
Add a link
Reference in a new issue