I've been scouring CPAN directly and via Google for a module that will iterate permutations in reverse order, but have come up empty. I would rather not roll my own.
I ask because I'm working on a search algorithm where I need to find the maximum permutation that meets the search criteria, but with ~8.7e10 permutations, searching them all is a huge waste.
I want to be able to do something like the below code. Of course Algorithm::Permute has no prev() method (nor does it actually guarantee any order), and neither do any of the other permutation/combinatorics modules I could find.
Alternatively, is there a clever way to (ab)use ascending permutations to get descending ones that I can't see right now?
use Algorithm::Permute;
say join ",",search(reverse (1..14));
sub search {
my $p = new Algorithm::Permute(\@_);
while (my @a = $p->prev) {
return @a if copasetic(@a);
}
}