Skip to content

Instantly share code, notes, and snippets.

@adntaha
Created March 10, 2026 05:20
Show Gist options
  • Select an option

  • Save adntaha/f592a9bf5a1a2eea5a70d6f5cfff8d16 to your computer and use it in GitHub Desktop.

Select an option

Save adntaha/f592a9bf5a1a2eea5a70d6f5cfff8d16 to your computer and use it in GitHub Desktop.
Naive implementation of the Collatz conjecture: if even, divide by two, if odd, times 3 plus 1, and you'll always end up in a 4, 2, 1 loop. Curious. I'm archiving this now but I made it a while ago (~12 november 2024)
def step(n: int) -> int:
return n*3+1 if n % 2 else n >> 1
for i in range(1, 1_000_000_000_000_000 + 1):
n = i
while n != 1:
n = step(n)
print(i, end=' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment