Skip to content

Add Steinhaus–Johnson–Trotter permutation generator - #15810

Open
gowthaambr wants to merge 1 commit into
TheAlgorithms:masterfrom
gowthaambr:steinhaus-johnson-trotter
Open

gowthaambr wants to merge 1 commit into
TheAlgorithms:masterfrom
gowthaambr:steinhaus-johnson-trotter

Conversation

@gowthaambr

@gowthaambr gowthaambr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests?
  • Documentation change?

Adds a lazy generator for permutations of 1 through n in Steinhaus–Johnson–Trotter order. Consecutive permutations differ by one adjacent swap. The doctests cover order, zero size, and invalid input.

Testing

Both checks passed in a local checkout of the PR branch.

  • uvx --with pytest pytest --doctest-modules maths/steinhaus_johnson_trotter.py
  • uvx pre-commit run --files maths/steinhaus_johnson_trotter.py

Checklist

  • Contribution guidelines reviewed while preparing this change.
  • Own-work attestation. The implementation and PR description were prepared with Codex assistance.
  • Automated tests are required to merge.
  • This PR adds one algorithm file in an existing directory.
  • Filename and identifiers follow Python naming conventions.
  • Function parameters and return values have type hints.
  • The function has doctests that pass locally.
  • The docstring links to the original paper.

No existing issue is linked to this proposal.

…son-Trotter permutation generator

Implement Steinhaus-Johnson-Trotter algorithm to generate permutations.
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Nov 25, 2026

This branch has not been deployed

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

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant