Staaarter

Generate Paperfolding Sequence

Generates N terms of the regular paperfolding sequence, the sequence of left/right creases produced by repeatedly folding a strip of paper in half, also known as the dragon curve sequence. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
sequencescombinatorics

Overview

Introduction

The regular paperfolding sequence turns a physical, hands-on activity, repeatedly folding a strip of paper in half, into a precise mathematical sequence with a surprisingly simple formula.

This generator computes any requested number of terms directly, using the sequence's closed-form rule rather than simulating actual paper folds.

What Is Generate Paperfolding Sequence?

The regular paperfolding sequence, cataloged as OEIS A014577, records the pattern of valley and mountain creases you'd see if you folded a strip of paper in half repeatedly, always in the same direction, then unfolded it flat.

It begins 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, ..., and is also called the dragon curve sequence because it encodes the exact turn-by-turn path of the classic dragon curve fractal.

How Generate Paperfolding Sequence Works

For each term index n, the tool repeatedly divides n by 2 until the result is odd, effectively stripping out all trailing factors of 2.

It then checks that odd number modulo 4: a remainder of 1 produces the term 1, and a remainder of 3 produces the term 0, a direct consequence of how each fold's crease direction depends on the binary structure of its position.

When To Use Generate Paperfolding Sequence

Use it when studying automatic sequences and their connection to geometric fractals, particularly alongside Dragon Curve Generator to see the same underlying sequence drawn out visually.

It's also a great classroom demonstration of how a hands-on physical activity, folding paper, maps directly onto a precise, computable mathematical sequence.

Features

Advantages

  • Uses a fast, exact closed-form computation for every term, no simulation of physical folds is needed.
  • Directly matches the canonical OEIS A014577 sequence, and by extension, the turn sequence of the dragon curve fractal.
  • Handles large term counts quickly since each term is computed independently of the others.

Limitations

  • Capped at 10,000 terms, chosen to keep the output a reasonable size to read, copy, or feed into a subsequent chained tool.
  • Outputs only the sequence's raw 0/1 values; it doesn't render the geometric fold pattern or curve itself, use Dragon Curve Generator for that visualization.

Examples

First 15 terms of the paperfolding sequence

Input

15

Output

1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0

These are the crease directions you'd read off a strip of paper folded in half four times, always in the same direction, then unfolded.

Best Practices & Notes

Best Practices

  • Generate a power-of-two-plus-some term count if you're trying to match a specific number of physical folds, since n folds produce 2^n - 1 creases.
  • Pair the output with Dragon Curve Generator if you want to see the same sequence rendered as the geometric fractal it describes.

Developer Notes

The core computation is `while (m % 2 === 0) m /= 2;` followed by a check of `m % 4`, an O(log n) per-term operation derived from the standard formula for the regular paperfolding sequence's nth term based on the 2-adic valuation of n.

Generate Paperfolding Sequence Use Cases

  • Studying automatic sequences and their closed-form formulas in combinatorics
  • Generating the turn sequence input for a dragon curve or other paperfolding-based fractal visualization
  • Classroom demonstrations connecting a physical paper-folding activity to a precise mathematical sequence

Common Mistakes

  • Assuming the sequence needs to be built by simulating folds step by step, the closed-form modulo-4 rule computes any term directly without that overhead.
  • Confusing this with the Prouhet-Thue-Morse sequence, both are classic automatic sequences over {0, 1}, but they're defined by entirely different rules and produce different term patterns.

Tips

  • If you're recreating the dragon curve by hand, generate exactly 2^n - 1 terms to match n physical paper folds.
  • Compare this sequence's structure against Prouhet-Thue-Morse Sequence Generator's output to see two different, equally famous automatic sequences over the same alphabet.

References

Frequently Asked Questions