Skip to content

fix: inverted loop condition in chaos_machine.py prevents execution#14777

Open
aeyjeyaryan wants to merge 1 commit into
TheAlgorithms:masterfrom
aeyjeyaryan:master
Open

fix: inverted loop condition in chaos_machine.py prevents execution#14777
aeyjeyaryan wants to merge 1 commit into
TheAlgorithms:masterfrom
aeyjeyaryan:master

Conversation

@aeyjeyaryan
Copy link
Copy Markdown

Describe your change:

Fixes an inverted while-loop condition in hashes/chaos_machine.py that prevented the output-pulling loop from ever executing.

  • Fix a bug or typo in an existing algorithm?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.

Summary of changes

Bug fix: The while-loop condition on line 98 was while inp in ("e", "E"):. Since inp is initialized as "", the loop never executed. Changed to while inp not in ("e", "E"):.

Additional improvements:

  • Added type hints to all functions (push, pull, reset)
  • Added a module-level docstring with references
  • Added docstrings with doctests to pull()
  • Fixed reset() to copy K with K.copy() instead of aliasing it (buffer_space = K), preventing mutation of the constant initial state on repeated reset() calls
  • Replaced deprecated typing.List with built-in list

All checks pass: ruff, ruff format, mypy, and doctest.

The while loop condition  was inverted — it
should be . The loop that pulls output
data and prompts the user for exit never executed.

Also:
- Add type hints to all functions
- Add module-level docstring with references
- Add docstrings with doctests to pull()
- Fix reset() to copy K instead of aliasing it (prevented repeated reset)
- Remove deprecated  in favor of built-in
@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Jun 8, 2026
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 enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant