Wiki

Clone wiki

dart_trotter / inverses

Home | Permutations | Combinations | Amalgams | Compositions | Subsets | Compounds | Inverses | About

Inverses

As of version 0.8.0, the trotter classes also encapsulate mappings from arrangements to integers via the indexOf method. This allows us to look up the index of given arrangements.

Here is an example that demonstrates looking up a permutation in a huge list of permutations:

var largeBagOfItems = characters("abcdefghijklmnopqrstuvwxyz");
var hugePseudoList = new Permutations(10, largeBagOfItems);

There are 19,275,223,968,000 permutatations of 10 letters taken from the Roman alphabet! Don't try to use a for loop on these!

The word algorithms is a permutation of ten distinct letters - where does it appear in the pseudo-list?

List algorithms = characters("algorithms");
int algorithmsIndex = hugePseudoList.indexOf(algorithms);
print("The index of $algorithms is $algorithmsIndex.\n");

Output:

The index of [a, l, g, o, r, i, t, h, m, s] is 6831894769563.

(That's almost seven trillion! Luckily we didn't have to use brute force to find it!)

Updated