Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wackywendell opened this issue Apr 25, 2014 · 0 comments
Closed

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

wackywendell opened this issue Apr 25, 2014 · 0 comments

Comments

@wackywendell
Copy link
Contributor

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]]
bors added a commit that referenced this issue Apr 27, 2014
I filed bugs #13734 and #13759 recently, and then realized I could probably fix them myself. This does exactly that, with a couple additional modifications and additions to the test-suite to pick up on that.

I've never done this before, so please feel free to tell me all the things I'm doing wrong or could be doing better.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant