Skip to content

[Bug] Collatz-Conjecture crashes on valid input 1 (StopIteration) + wrong output on reuse #1868

Description

@vedant7007

Problem (High — crash on valid input 1)

math/Collatz-Conjecture/Collatz-Conjecture.py:26 — the cache branch does yield from get_remaining_sequence(start), but that helper yields the sequence after start and never start itself. Input 1 is always in steps_cache ({1: 0}), so the generator yields nothing, and first = next(gen) at line 95 raises an uncaught StopIteration and the program crashes. 1 passes every input guard, so it's valid.

Separately, a number reused within a session (e.g. 6 then 3) prints a sequence missing its starting term and an off-by-one step count.

Suggested fix (tiny)

In the cache branch, yield start before yield from get_remaining_sequence(start).

Would love to fix under GSSoC '26.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions