Skip to content

Permutations of [1 element] should not be empty #13759

Closed
@wackywendell

Description

@wackywendell

The permutations of [x] should be the list [[x]].

Additionally, I would also expect the permutations of [] to be [[]] (as it is in python, which also matches 0! = 1! = 1).

Currently, the permutations function (std::slice::ImmutableCloneableVector::permutations) returns [] in both cases.

Example code:

fn main(){
    let clists = [~[], ~['x'], ~['x','y']];

    for clist in clists.iter(){
        let perms : Vec<~[char]> = clist.permutations().collect();
        println!("Permutations of {}: {}", clist, perms);
    }
}

Prints out

Permutations of []: []
Permutations of [x]: []
Permutations of [x, y]: [[x, y], [y, x]]

Instead of the expected

Permutations of []: [[]]
Permutations of [x]: [[x]]
Permutations of [x, y]: [[x, y], [y, x]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions