Algorithm-Combinatorics
view release on metacpan or search on metacpan
Combinatorics.xs view on Meta::CPAN
return k;
}
/**
* The only algorithms I have found by now are either recursive, or a
* naive wrapper around permutations() that loops over all of them and
* discards the ones with fixed-points.
*
* We take here a mixed-approach, which consists on starting with the
* algorithm in __next_permutation() and tweak a couple of places that
* allow us to skip a significant number of permutations sometimes.
*
* Benchmarking shows this subroutine makes derangements() more than
* two and a half times faster than permutations() for n = 8.
*/
int __next_derangement(SV* tuple_avptr)
{
AV* tuple = GETAV(tuple_avptr);
I32 max_n, min_j, j, h, k;
Combinatorics.xs view on Meta::CPAN
adjust = 1 - n;
SETIV(odometer, i, adjust);
}
}
return (AV*) sv_2mortal((SV*) subset);
}
/** -------------------------------------------------------------------
*
* XS stuff starts here.
*
*/
MODULE = Algorithm::Combinatorics PACKAGE = Algorithm::Combinatorics
PROTOTYPES: DISABLE
int
__next_combination(tuple_avptr, max_n)
SV* tuple_avptr
int max_n
( run in 0.292 second using v1.01-cache-2.11-cpan-0d8aa00de5b )