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

New puzzle: next permutation in lexicographical order #7

Open
TalSchuster opened this issue Jun 17, 2021 · 1 comment
Open

New puzzle: next permutation in lexicographical order #7

TalSchuster opened this issue Jun 17, 2021 · 1 comment

Comments

@TalSchuster
Copy link
Contributor

def sat(nx: List[int], x=[1, 2, 4, 3]): 
    """Find the next permutation of a given list by lexicographical ordering."""
    import itertools
    assert len(x) == len(nx) and set(x) == set(nx)
    return x < nx and all([list(perm) <= x or list(perm) >= nx for perm in list(itertools.permutations(x))])
Reveal solution
def sol():
    return [1, 3, 2, 4]
Reveal solution
def sol():
    import itertools
    perms = sorted([list(p) for p in list(itertools.permutations(x))])
    return perms[perms.index(x) + 1]

Solvers, post your solutions in the comments using the following formatting:

<details><summary>Reveal solution</summary>

```python
def sol():
    return "world"  # replace with your solution
```
</details>
@akalai
Copy link
Contributor

akalai commented Jun 18, 2021

Nice one!

Reveal solution
def sol():
    return [1, 3, 2, 4]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants