permutation

Iterator to generate all permutations for a provided array
https://github.com/tjwlucas/haxe-permutation

To install, run:

haxelib install permutation 0.1.0 

See using Haxelib in Haxelib documentation for more information.

README.md

haxe-permutation

A simple libary tha provides a single Permuter class to generate all permutations for a provided array (Starting with the original).

Nothing target-specific has been used, so in theory, every haxe target should be supported. It is specifically tested in php (7 & 8), neko, python & javascript

:warning: Any given array of length n will have n! permutations. As a result, looping through all permutations will get very heavy for all but the shortest arrays (e.g. 6! = 720, 7! = 5040, 8! = 40320, 10! = 3628800 etc.), so think very carefully about looping over all permutations without a break condition.

Usage

import permutation.Permuter;
var example_array = [1,2,3];
var permuter = new Permuter(example_array);
for (permutation in permuter) {
    trace(permutation);
}

Outputs:

Example.hx:5: [1,2,3]
Example.hx:5: [2,1,3]
Example.hx:5: [3,1,2]
Example.hx:5: [1,3,2]
Example.hx:5: [2,3,1]
Example.hx:5: [3,2,1]

Duplicate entries are not considered, so:

var example_array = [1,1,2];
var permuter = new permutation.Permuter(example_array);
for(permutation in permuter) {
    trace(permutation);
}

Will result in:

Example.hx:5: [1,1,2]
Example.hx:5: [1,1,2]
Example.hx:5: [2,1,1]
Example.hx:5: [1,2,1]
Example.hx:5: [1,2,1]
Example.hx:5: [2,1,1]
Contributors
tlucas
Version
0.1.0
Published
3 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub