Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

New puzzle: next permutation in lexicographical order #7

Description

@TalSchuster
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>

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions