Skip to content

Add permute to standard library #1013

Closed
@jdm

Description

@jdm

It's too much effort to create a branch and pull request at this point, so I'll paste the code I've been using inline:

iter permute(elts: [@T]) -> [@T] {
    if vec::is_not_empty(elts) {
        for each i in uint::range(0u, vec::len(elts)) {
            let rest = vec::slice(elts, 0u, i);
            rest += vec::slice(elts, i + 1u, vec::len(elts));
            for each permutation in permute(tmp) {
                put [elts[i]] + permutation;
            }
        }        
    } else {
        put [];
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions