Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
15
Task/Permutation-test/D/permutation-test-1.d
Normal file
15
Task/Permutation-test/D/permutation-test-1.d
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import std.stdio, std.algorithm, std.array, combinations3;
|
||||
|
||||
auto permutationTest(T)(in T[] a, in T[] b) pure nothrow @safe {
|
||||
immutable tObs = a.sum;
|
||||
auto combs = combinations!false(a ~ b, a.length);
|
||||
immutable under = combs.count!(perm => perm.sum <= tObs);
|
||||
return under * 100.0 / combs.length;
|
||||
}
|
||||
|
||||
void main() {
|
||||
immutable treatmentGroup = [85, 88, 75, 66, 25, 29, 83, 39, 97];
|
||||
immutable controlGroup = [68, 41, 10, 49, 16, 65, 32, 92, 28, 98];
|
||||
immutable under = permutationTest(treatmentGroup, controlGroup);
|
||||
writefln("Under =%6.2f%%\nOver =%6.2f%%", under, 100.0 - under);
|
||||
}
|
||||
24
Task/Permutation-test/D/permutation-test-2.d
Normal file
24
Task/Permutation-test/D/permutation-test-2.d
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
void main() @safe {
|
||||
import std.stdio, std.algorithm, std.range;
|
||||
|
||||
immutable treatment = [85, 88, 75, 66, 25, 29, 83, 39, 97];
|
||||
immutable control = [68, 41, 10, 49, 16, 65, 32, 92, 28, 98];
|
||||
immutable both = treatment ~ control;
|
||||
immutable sTreat = treatment.sum;
|
||||
|
||||
T pick(T)(in size_t at, in size_t remain, in T accu) pure nothrow @safe @nogc {
|
||||
if (remain == 0)
|
||||
return accu > sTreat;
|
||||
|
||||
return pick(at - 1, remain - 1, accu + both[at - 1]) +
|
||||
(at > remain ? pick(at - 1, remain, accu) : 0);
|
||||
}
|
||||
|
||||
alias mul = reduce!q{a * b};
|
||||
immutable t = mul(1.0, iota(both.length, treatment.length + 1, -1))
|
||||
.reduce!q{a / b}(iota(treatment.length, 0, -1));
|
||||
immutable gt = pick(both.length, treatment.length, 0);
|
||||
immutable le = cast(int)(t - gt);
|
||||
writefln(" > : %2.2f%% %d", 100.0 * gt / t, gt);
|
||||
writefln("<= : %2.2f%% %d", 100.0 * le / t, le);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue