Collatz Conjecture Calculator – Trace the 3n+1 Sequence
The Collatz conjecture, also known as the 3n+1 problem or the hailstone sequence, is one of the most famous unsolved problems in number theory — despite being simple enough to explain to a child. Pick any positive whole number. If it is even, divide it by two; if it is odd, triple it and add one. Repeat the process on whatever number you get. The conjecture claims that no matter which starting number you pick, you will always eventually reach 1. This calculator automates that trace, so you can explore the pattern for any starting integer without tallying dozens of steps by hand.
How the Rule Is Applied
The core rule is a single conditional step repeated until the sequence bottoms out: n → n / 2 when n is even, and n → 3n + 1 when n is odd. Starting from 27, for example, the sequence climbs and falls through 111 steps before reaching 1, peaking at 9,232 — over 340 times the starting value — along the way. That erratic rise-and-fall pattern is why the trace is nicknamed a hailstone sequence: like a hailstone bouncing up and down inside a storm cloud before it finally falls to the ground.
Total Stopping Time and Peak Value
Two numbers summarize any Collatz trace. The total stopping time is simply how many steps it takes to first reach 1. The peak value is the largest number the sequence touches before it descends — often far larger than the starting number, since a run of consecutive odd steps can multiply the value by nearly three each time before an even step brings it back down. This calculator reports both figures instantly, along with the exact step at which the peak occurred and a breakdown of how many odd (3n+1) versus even (n/2) steps were applied.
Fast Mode and BigInt Precision
For very large starting numbers, generating and rendering the entire sequence can be unnecessary overhead. Switching off "show full sequence" puts the calculator into a fast stopping-time-only modethat returns just the step count and peak value without storing every intermediate term. Under the hood, every calculation uses JavaScript's BigInt type rather than ordinary numbers, because intermediate values from the 3n+1 step can exceed Number.MAX_SAFE_INTEGEReven for starting numbers well within this tool's 1015 limit — keeping every result mathematically exact instead of approximated.
Range Analysis and Record Holders
Beyond tracing a single number, the range/batch mode computes the stopping time and peak value for every integer across a chosen span — up to 10,000 numbers at once — and automatically flags whichever starting number took the longest to reach 1, and whichever climbed to the highest peak. This is a popular way to hunt for local "records," such as discovering that 27 is the longest-running starting number under 100. To keep a large batch responsive, the calculator memoizes results: since many Collatz sequences merge into a shared tail on the way down (every sequence that reaches 16 continues 16, 8, 4, 2, 1), computing one number's stopping time can reuse work already done for an earlier one.
Parity Patterns and Step-Through Viewing
Toggling the parity pattern display renders each step as an odd or even marker, giving a compact visual of the sequence's underlying binary-like structure. The step-through animation control lets you walk through a sequence one iteration at a time with play, pause, and skip controls — handy for teaching the rule or double-checking a manual calculation. Results can be copied, downloaded as a text summary, exported as CSV for spreadsheet analysis, or shared via a link that restores your exact inputs for someone else.
Practical Limits
Starting numbers are accepted up to 1015, and a configurable max-steps safety limit (10,000 by default, adjustable to 100,000) prevents the browser from freezing if an edge case runs unexpectedly long. Range analysis is capped at 10,000 starting numbers per batch to keep the results table responsive and legible.