Skip to content

fix : prevent duplicate values in Collatz sequence generator for cached starts - #1811

Merged
steam-bell-92 merged 1 commit into
steam-bell-92:mainfrom
tmdeveloper007:#1806
Jul 27, 2026
Merged

fix : prevent duplicate values in Collatz sequence generator for cached starts#1811
steam-bell-92 merged 1 commit into
steam-bell-92:mainfrom
tmdeveloper007:#1806

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Summary of What Has Been Done

In math/Collatz-Conjecture/Collatz-Conjecture.py, replaced the manual loop in the if start in steps_cache: branch of collatz_sequence with yield from get_remaining_sequence(start). The original code yielded start manually, then separately called get_remaining_sequence(n) which yielded from collatz_next(start) onward — skipping start in the remaining sequence and causing duplicate values in the final output.

Changes Made

     if start in steps_cache:
-        n = start
-        yield n
-        while n != 1:
-            n = collatz_next(n)
-            yield n
-        return
+        yield from get_remaining_sequence(start)
+        return

Impact it Made

  • Correct Collatz sequence output without duplicate values when the starting number is already cached.
  • All existing tests continue to pass (115/115).

Closes #1806.

Note: Please assign this PR to the tmdeveloper007 account.

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Anuj's projects Team on Vercel.

A member of the Team first needs to authorize it.

@steam-bell-92
steam-bell-92 merged commit 26d16fa into steam-bell-92:main Jul 27, 2026
1 check failed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Thank you for your contribution!

Your Pull Request has been merged successfully.
Thanks again for your support! 🙌

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

Successfully merging this pull request may close these issues.

fix: prevent duplicate sequence values in collatz_sequence generator for cached starts

2 participants