Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
T[][] ncsub(T)(in T[] seq, in uint s=0) pure nothrow @safe {
|
||||
if (seq.length) {
|
||||
typeof(return) aux;
|
||||
foreach (ys; ncsub(seq[1 .. $], s + !(s % 2)))
|
||||
aux ~= seq[0] ~ ys;
|
||||
return aux ~ ncsub(seq[1 .. $], s + s % 2);
|
||||
} else
|
||||
return new typeof(return)(s >= 3, 0);
|
||||
}
|
||||
|
||||
void main() @safe {
|
||||
import std.stdio;
|
||||
|
||||
[1, 2, 3].ncsub.writeln;
|
||||
[1, 2, 3, 4].ncsub.writeln;
|
||||
foreach (const nc; [1, 2, 3, 4, 5].ncsub)
|
||||
nc.writeln;
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
struct Ncsub(T) {
|
||||
T[] seq;
|
||||
|
||||
int opApply(int delegate(ref T[]) dg) const {
|
||||
immutable n = seq.length;
|
||||
int result;
|
||||
auto S = new T[n];
|
||||
|
||||
OUTER: foreach (immutable i; 1 .. 1 << n) {
|
||||
uint lenS;
|
||||
bool nc = false;
|
||||
foreach (immutable j; 0 .. n + 1) {
|
||||
immutable k = i >> j;
|
||||
if (k == 0) {
|
||||
if (nc) {
|
||||
auto auxS = S[0 .. lenS];
|
||||
result = dg(auxS);
|
||||
if (result)
|
||||
break OUTER;
|
||||
}
|
||||
break;
|
||||
} else if (k % 2) {
|
||||
S[lenS] = seq[j];
|
||||
lenS++;
|
||||
} else if (lenS)
|
||||
nc = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
import std.array, std.range;
|
||||
|
||||
//assert(24.iota.array.Ncsub!int.walkLength == 16_776_915);
|
||||
auto r = 24.iota.array;
|
||||
uint counter = 0;
|
||||
foreach (s; Ncsub!int(r))
|
||||
counter++;
|
||||
assert(counter == 16_776_915);
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
import std.stdio, std.array, std.range, std.concurrency;
|
||||
|
||||
Generator!(T[]) ncsub(T)(in T[] seq) {
|
||||
return new typeof(return)({
|
||||
immutable n = seq.length;
|
||||
auto S = new T[n];
|
||||
|
||||
foreach (immutable i; 1 .. 1 << n) {
|
||||
uint lenS = 0;
|
||||
bool nc = false;
|
||||
foreach (immutable j; 0 .. n + 1) {
|
||||
immutable k = i >> j;
|
||||
if (k == 0) {
|
||||
if (nc)
|
||||
yield(S[0 .. lenS]);
|
||||
break;
|
||||
} else if (k % 2) {
|
||||
S[lenS] = seq[j];
|
||||
lenS++;
|
||||
} else if (lenS)
|
||||
nc = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
assert(24.iota.array.ncsub.walkLength == 16_776_915);
|
||||
|
||||
[1, 2, 3].ncsub.writeln;
|
||||
[1, 2, 3, 4].ncsub.writeln;
|
||||
foreach (const nc; [1, 2, 3, 4, 5].ncsub)
|
||||
nc.writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue