Staaarter

Generate Rudin-Shapiro Sequence

Generates the first N terms of the Rudin-Shapiro sequence, a +1/-1 automatic sequence defined by the parity of overlapping "11" pairs in each index's binary representation. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
sequencesnumber-theory

Overview

Introduction

The Rudin-Shapiro sequence is a classic +1/-1 sequence built directly from the binary digits of the index, best known for having much smaller partial sums than a typical random +1/-1 sequence would.

This tool generates as many terms as you need, computing each one from scratch off its index's binary representation rather than any recursive lookup table.

What Is Generate Rudin-Shapiro Sequence?

It is a 2-automatic sequence: a sequence whose n-th term can be read off a finite-state machine fed the binary digits of n. Term(n) is +1 or -1 depending on whether n's binary form contains an even or odd number of overlapping "11" pairs.

It was discovered independently by Marcel Golay, Harold Shapiro, and Walter Rudin around the 1950s, and shows up in analysis, combinatorics on words, and digital signal processing.

How Generate Rudin-Shapiro Sequence Works

For each index n from 0 up to count - 1, the tool converts n to a binary string using standard base-2 conversion.

It then scans that string for occurrences of the substring "11", counting overlapping matches (so the binary string "111" contributes two matches: positions 0-1 and 1-2).

If the total count of "11" occurrences is even, the term is recorded as +1; if odd, it's recorded as -1.

When To Use Generate Rudin-Shapiro Sequence

Use it when you need a concrete, verifiable list of Rudin-Shapiro terms for a homework problem, a signal-processing experiment, or to sanity-check a from-scratch implementation.

It's also a handy way to explore automatic sequences generally, since the same overlapping-substring-count idea generalizes to other automatic sequences built on different binary patterns.

Features

Advantages

  • Computes every term directly from its index's binary form, so there's no accumulated floating-point or recursive-lookup error.
  • Handles up to 10,000 terms in one pass, more than enough for most classroom or exploratory uses.

Limitations

  • Term count is capped at 10,000 to keep the browser responsive; extremely long runs aren't supported.
  • Only the 0-indexed convention (n starting at 0) is offered; there's no option to start indexing at 1.

Examples

First 8 terms

Input

8

Output

+1, +1, +1, -1, +1, +1, -1, +1

n = 0 ("0"), 1 ("1"), and 2 ("10") each have zero "11" pairs, so +1. n = 3 ("11") has one pair, so -1. n = 4, 5 ("100", "101") have zero pairs, so +1. n = 6 ("110") has one pair, so -1. n = 7 ("111") has two overlapping pairs, an even count, so +1.

Best Practices & Notes

Best Practices

  • If you're comparing against a published table, double-check whether that source indexes from 0 or 1, since the sequence's values differ by a shift.

Developer Notes

The implementation is a direct, unmemoized scan: for each n it calls `n.toString(2)` and walks the resulting string once, incrementing a counter whenever `s[i]` and `s[i+1]` are both "1". Parity of that counter determines the sign. There's no recursive or bitwise trick beyond ordinary string scanning, since clarity and easy verification matter more than micro-optimization for a tool capped at 10,000 terms.

Generate Rudin-Shapiro Sequence Use Cases

  • Generating reference values to validate a Rudin-Shapiro implementation in another language
  • Exploring bounded partial-sum behavior in a number theory course
  • Producing a flat-spectrum +1/-1 sequence for a signal-processing demo

Common Mistakes

  • Counting non-overlapping "11" pairs instead of overlapping ones; "111" has two overlapping pairs, not one, and that distinction changes the parity and the resulting sign.

Tips

  • Cross-check small term counts (like the first 8) against OEIS A020985 before trusting a larger run.

References

Frequently Asked Questions