Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -4,7 +4,7 @@ struct Spermutations(bool doCopy=true) {
|
|||
private immutable uint n;
|
||||
alias TResult = Tuple!(int[], int);
|
||||
|
||||
int opApply(in int delegate(in ref TResult) dg) {
|
||||
int opApply(in int delegate(in ref TResult) nothrow dg) nothrow {
|
||||
int result;
|
||||
|
||||
int sign = 1;
|
||||
|
|
@ -18,18 +18,16 @@ struct Spermutations(bool doCopy=true) {
|
|||
if (result)
|
||||
goto END;
|
||||
|
||||
while (p.canFind!q{ a[1] }) {
|
||||
while (p.any!q{ a[1] }) {
|
||||
// Failed to use std.algorithm here, too much complex.
|
||||
auto largest = Int2(-100, -100);
|
||||
int i1 = -1;
|
||||
foreach (immutable i, immutable pi; p) {
|
||||
if (pi[1]) {
|
||||
foreach (immutable i, immutable pi; p)
|
||||
if (pi[1])
|
||||
if (pi[0] > largest[0]) {
|
||||
i1 = i;
|
||||
largest = pi;
|
||||
}
|
||||
}
|
||||
}
|
||||
immutable n1 = largest[0],
|
||||
d1 = largest[1];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,33 @@
|
|||
import std.algorithm, std.array, std.typecons, std.range;
|
||||
|
||||
auto sPermutations(in int n) /*pure nothrow*/ {
|
||||
static int[][] sPermu(in int items) /*pure nothrow*/ {
|
||||
auto sPermutations(in uint n) pure nothrow @safe {
|
||||
static immutable(int[])[] inner(in int items) pure nothrow @safe {
|
||||
if (items <= 0)
|
||||
return [[]];
|
||||
typeof(return) r;
|
||||
foreach (immutable i, item; sPermu(items - 1)) {
|
||||
//r.put((i % 2 ? iota(cast(int)item.length, -1, -1) :
|
||||
foreach (immutable i, immutable item; inner(items - 1)) {
|
||||
//r.put((i % 2 ? iota(item.length.signed, -1, -1) :
|
||||
// iota(item.length + 1))
|
||||
// .map!(i => item[0..i] ~ (items-1) ~ item[i..$]));
|
||||
immutable f=(in int i)=>item[0..i] ~ (items-1) ~ item[i..$];
|
||||
// .map!(i => item[0 .. i] ~ (items - 1) ~ item[i .. $]));
|
||||
immutable f = (in size_t i) pure nothrow @safe =>
|
||||
item[0 .. i] ~ (items - 1) ~ item[i .. $];
|
||||
r ~= (i % 2) ?
|
||||
iota(cast(int)item.length, -1, -1).map!f.array :
|
||||
//iota(item.length.signed, -1, -1).map!f.array :
|
||||
iota(item.length + 1).retro.map!f.array :
|
||||
iota(item.length + 1).map!f.array;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
return sPermu(n).zip([1, -1].cycle);
|
||||
return inner(n).zip([1, -1].cycle);
|
||||
}
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
foreach (immutable n; [3, 4]) {
|
||||
writefln("\nPermutations and sign of %d items", n);
|
||||
foreach (const tp; n.sPermutations)
|
||||
writefln("Perm: %s Sign: %2d", tp[]);
|
||||
foreach (immutable n; [2, 3, 4]) {
|
||||
writefln("Permutations and sign of %d items:", n);
|
||||
foreach (immutable tp; n.sPermutations)
|
||||
writefln(" %s Sign: %2d", tp[]);
|
||||
writeln;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue