Skip to content
πŸ› οΈToolsShed

Collatz Sequence Visualizer

Visualize the Collatz conjecture sequence for any starting number.

About this tool

The Collatz Conjecture Visualizer lets you explore one of the most famous unsolved problems in mathematics. Starting from any whole number, it repeatedly halves even numbers and triples-plus-one odd numbers, and the conjecture claims every sequence eventually reaches 1. This tool turns that abstract rule into a sequence you can actually watch unfold.

To use it, enter a starting number and the tool generates the full Collatz sequence, showing its total length and the peak value it reaches on a chart. It is well suited for students learning about iterative processes, math enthusiasts curious about chaotic-looking patterns, and teachers demonstrating the conjecture in class.

One fascinating tip is that even small starting numbers can spike to surprisingly large peaks before falling back down to 1. Everything runs locally in your browser, so you can experiment freely with as many numbers as you like.

Frequently Asked Questions

Code Implementation

def collatz_sequence(n):
    seq = [n]
    while n != 1:
        n = n // 2 if n % 2 == 0 else 3 * n + 1
        seq.append(n)
    return seq

n = 27
seq = collatz_sequence(n)
print(f"Starting number: {n}")
print(f"Steps to reach 1: {len(seq) - 1}")
print(f"Peak value: {max(seq)}")
print(f"Sequence: {seq[:10]}... (showing first 10)")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.