Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions math/collatz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Collatz sequence.

@author: Pablo Trinidad <github.com/pablotrinidad>
"""


def collatz(n):
"""Sequence generation."""
l = []
while n > 1:
l.append(n)
if n % 2 == 0:
n = n / 2
else:
n = (3 * n) + 1
l.append(n)
return l

n = int(input("Enter an integer n to compute the Collatz sequence: "))
print(collatz(n))