Paperfolding Sequence Calculator
Sequences
- The regular paperfolding sequence records the valley (1) and mountain (0) folds of a strip folded in half again and again, always in the same direction.
- Write n = m x 2^k with m odd: here 10 = 5 x 2^1, so m = 5 and m mod 4 = 1.
- The rule is a(n) = 1 when m is 1 mod 4 and 0 when m is 3 mod 4, giving a(10) = 1.
- The sequence is also the dragon-curve turn sequence: read 1 as a left turn and 0 as a right turn and the folds trace the Heighway dragon fractal.
Fold a strip of paper in half, then in half again, always in the same direction, and unfold it. The creases alternate between valleys and mountains in a pattern that never becomes periodic: 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, ... This is the regular paperfolding sequence, with 1 for a valley fold and 0 for a mountain fold.
The miracle is that no folding is needed to compute it. Write n = m x 2^k with m odd; then a(n) = 1 when m is 1 mod 4 and 0 when m is 3 mod 4. For n = 10: 10 = 5 x 2^1 and 5 mod 4 = 1, so a(10) = 1. For n = 12: 12 = 3 x 2^2 and 3 mod 4 = 3, so a(12) = 0.
This paperfolding sequence calculator applies the odd-part rule directly and can list the first n folds with their valley and mountain counts - the first 16 terms hold 9 valleys and 7 mountains. The same sequence, read as left and right turns, traces the Heighway dragon fractal.
Worked examples
The 10th fold
(Value at n · 10)
| paperfolding value a(10) | 1 |
| odd part m of n = m x 2^k | 5 |
| exponent k (factors of two in n) | 1 |
| m mod 4 | 1 |
The 12th fold
(Value at n · 12)
| paperfolding value a(12) | 0 |
| odd part m of n = m x 2^k | 3 |
| exponent k (factors of two in n) | 2 |
| m mod 4 | 3 |
First 16 folds
(First n terms · 16)
| first 16 paperfolding terms | 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1 |
| ones (valley folds) | 9 |
| zeros (mountain folds) | 7 |
| last term | 1 |
Valleys and mountains
One fold makes one crease. Two folds make three creases: valley, valley, mountain - reading the unfolded strip in order. Three folds make seven creases, four folds fifteen: the counts 1, 3, 7, 15 are one less than powers of two, because each folding doubles the layers and adds the new centre crease. The sequence records the crease types of the fully folded strip in spatial order.
The convention used here is 1 for a valley (the crease opens upward, like a V) and 0 for a mountain (like a tent). Other sources swap the symbols or read the strip from the other end, which flips or reverses the sequence; the calculator's convention is stated on the page and used consistently, and the odd-part rule below matches it exactly.
- 1 = valley fold, 0 = mountain fold
- k foldings give 2^k - 1 creases
- Always fold in the same direction
The odd-part rule
Every positive integer factors uniquely as n = m x 2^k with m odd. The paperfolding value depends only on m mod 4: if the odd part is 1 mod 4, the fold is a valley (1); if 3 mod 4, a mountain (0). The exponent k - the number of factors of two in n - is reported by the calculator as supporting evidence but does not affect the answer beyond locating m.
Worked: n = 10 factors as 5 x 2^1, m = 5, 5 mod 4 = 1, valley. n = 12 factors as 3 x 2^2, m = 3, 3 mod 4 = 3, mountain. n = 7 is already odd: m = 7, 7 mod 4 = 3, so a(7) = 0 - and indeed the seventh term of the listed sequence is 0.
- n = m x 2^k, m odd
- m mod 4 = 1 -> valley (1); m mod 4 = 3 -> mountain (0)
- a(10) = 1; a(12) = 0; a(7) = 0
The first 16 folds
The first 16 terms are 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1: nine valleys and seven mountains. The near-balance is structural - the folding process creates valleys and mountains in almost equal numbers, with valleys slightly ahead in every prefix of this regular folding.
Look for periodicity and you will not find it: blocks that seem to repeat return with a twist. The sequence is automatic - generated by a finite-state process - yet aperiodic, one of the standard examples that 'automatic' and 'eventually repeating' are different properties. It is also cube-free-adjacent in the family of folding sequences studied alongside Thue-Morse.
- First 16: 9 valleys, 7 mountains
- Automatic but never periodic
- Valleys lead in every prefix
The dragon curve
Read the sequence as instructions to a turtle: at each crease, turn left for 1 and right for 0, walking unit steps. The path never crosses itself and folds into the Heighway dragon - the fractal curve popularised by Martin Gardner, formed (literally) by the folded strip viewed edge-on. The paperfolding sequence is the dragon's turn sequence, and the odd-part rule is the fractal's arithmetic skeleton.
This is why the sequence appears in computer graphics and procedural generation: a one-line arithmetic rule that unfolds into a space-filling-adjacent fractal. The calculator's list mode gives you the raw turns; any turtle-graphics environment turns them into the dragon in a dozen lines.
The dragon connection runs both ways: because the turn sequence has the closed odd-part rule, properties of the fractal - its dimension, its self-similarity at every scale, the fact that four copies of the curve interlock to tile the plane - can be approached through the arithmetic of n rather than through geometry alone. A crease pattern, a number-theoretic rule and a fractal are three descriptions of one object, and this page's calculator works with the description that fits in a single line.
- 1 = left turn, 0 = right turn
- Traces the Heighway dragon curve
- The folded strip edge-on is the fractal
Folding in the other direction, and other variants
Fold the strip the opposite way at every step and the sequence complements: valleys and mountains swap, giving the mirror-image dragon. Alternate the folding direction and a different, related sequence appears. The 'regular' sequence on this page is the same-direction case, the canonical one, with the odd-part rule as stated.
If you compare against another source and the terms disagree, check conventions before doubting the arithmetic: symbol swap (0 for valley), reading direction (the strip read right-to-left reverses the sequence), and starting index (some authors index the first crease as term 0) account for nearly all discrepancies. Under this page's conventions, a(10) = 1 and a(12) = 0 are the reference values.
- Opposite folding complements the sequence
- Convention mismatches explain most disagreements
- Reference values here: a(10) = 1, a(12) = 0
Why the odd part decides
The rule looks arbitrary until the folding is thought of recursively. The crease at position n sits inside a stack whose local geometry is determined by how many times the paper was folded after that crease was made - and that is counted by the power of two dividing n. Stripping the factors of two removes the later foldings; what remains, the odd part m, encodes the crease's position within the first-fold pattern, and m mod 4 distinguishes the two orientations that the first fold can leave behind.
This is the same arithmetic skeleton as the ruler function and the Thue-Morse parity: strip the 2s, look at what is left. The three sequences are cousins - the paperfolding sequence reads the odd part mod 4, Thue-Morse reads the parity of the binary digit sum, and the ruler function reads the exponent k itself. One family of questions about the 2-adic structure of n, three different readouts, three different sequences - the calculator reports m, k and m mod 4 together so the kinship is visible in every answer.
- Factors of two count later foldings
- The odd part encodes the first-fold pattern
- Cousins: ruler function, Thue-Morse parity
Using the calculator
Value mode returns a(n) with the factorisation evidence: the odd part m, the exponent k, and m mod 4 - the whole rule, displayed. List mode gives the first n terms with valley and mountain counts. Terms up to n = 500 are supported; the computation is a single factorisation per term.
A satisfying check: the terms at odd positions are governed directly by the position's own residue - a(5): 5 mod 4 = 1, valley; a(7): 7 mod 4 = 3, mountain; a(9): 9 mod 4 = 1, valley - and the listed first 16 terms agree: positions 5, 7, 9 read 1, 0, 1.
- Value mode shows m, k and m mod 4
- List mode with valley/mountain counts
- Odd positions read straight off n mod 4
FAQs
How is the paperfolding sequence defined?
Write n = m x 2^k with m odd. Then a(n) = 1 (valley) if m is 1 mod 4, and 0 (mountain) if m is 3 mod 4.
What is the 10th paperfolding term?
a(10) = 1: 10 = 5 x 2^1 and the odd part 5 is 1 mod 4, a valley fold.
What are the first paperfolding terms?
1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1 - with 9 valley folds and 7 mountain folds among the first 16.
What do the 1s and 0s mean physically?
1 is a valley fold and 0 is a mountain fold in a strip folded in half repeatedly in the same direction, read in spatial order after unfolding.
How does the sequence relate to the dragon curve?
It is the dragon curve's turn sequence: read 1 as a left turn and 0 as a right turn and the folds trace the Heighway dragon fractal.
How many valley folds are in the first 16 terms?
9 valleys and 7 mountains - valleys stay slightly ahead in every prefix of the regular folding.