Deja-Vu Detector

random streams can feel eerily familiar

Loading interactive simulation...

Certainty needs 120 symbols. Even money needs 13. 🖖

Pigeonhole says when a repeat becomes unavoidable: with 64 possible three-symbol windows, a 120-symbol run holds 118 windows and cannot dodge one. It says nothing about when a repeat becomes likely β€” that is the birthday bound, and it lands far earlier, around 1.177 Γ— √64 β‰ˆ 9 windows. Push 200,000 random sequences through this tool’s own window counter and the crossover sits at length 13: 11 windows, 51.2%. The shortest sequence it will draw, 10 symbols, already repeats 30.5% of the time, and its smallest preset of 30 symbols repeats 99.6% of the time. Familiarity does not wait for the guarantee.

Why familiar patterns are unavoidable 🖖

That flash of 'I've seen this before' is your brain's pattern-matcher firing, but in a short stream built from only 4 symbols, local repeats are ordinary rather than eerie. With window size 3 there are just 43 = 64 possible patterns, so a 120-symbol run (118 windows) is forced to repeat at least one by the pigeonhole principle. This tool counts the real repeats and compares them against a random baseline, separating genuine surprise from routine chance.

Some patterns clump more than others 🖖

Two windows of the same length are not equally prone to bunching up. A self-overlapping motif like AAAA or ABAB can line up with a shifted copy of itself, so once it appears it tends to recur immediately, giving it higher variance in its repeat count than a non-overlapping window like ABCD. Guibas and Odlyzko captured this with a pattern's autocorrelation. So the dΓ©jΓ  vu you feel depends on which motif recurs, not merely how long it is.

Problem solved in full

  1. A 3-symbol window sliding along a stream of 50 symbols 6 steps

    A stream of 50 symbols is drawn from the 4 letters A, B, C, D, and a 3-symbol window slides along it. This is the panel's length 50, window 3 state. How many of those windows should show a pattern that has already appeared? Derive the count, then find the shortest stream for which a repeat is already better than even money.

    1. Count the windows before counting anything else. A 3-symbol window can start at position 1 and at every position up to 48, because starting at 49 runs it off the end. That gives 48 windows, and 48 is the denominator every repeat count on the panel is reported against.

    2. Now count what they could be. 3 slots, 4 letters each, so 64 patterns exist. There are fewer windows than patterns, which means nothing forces a repeat β€” the pigeonhole argument gives you nothing here, and whatever happens is chance.

    3. Turn the question inside out and ask about one pattern, say ABD. A single window fails to be ABD with probability 63/64. Treat the 48 windows as independent draws, as the panel's own expectation does, and they all fail together with probability (63/64)48 = 0.4696, so ABD turns up at least once with probability 1 βˆ’ 0.4696 = 0.5304.

    4. That 0.5304 is the chance for every pattern equally, so multiply it by all 64 of them to get the expected number of distinct patterns the stream actually contains.

    5. A window is a repeat exactly when its pattern has been seen before, so each pattern that is present contributes precisely one window that is not a repeat. Subtract the distinct patterns from the total windows and the repeats fall out.

    6. A second route explains why the answer is so large. Instead of asking about patterns, ask about pairs of windows: any two windows carry the same 3 symbols with probability 1/64, and there are 1128 pairs to try.

    Answer

    14.05 of the 48 windows repeat, and 17.6 expected matching pairs is why that is not a near miss. Run the pair count backwards to find where a repeat first becomes better than even money. A count with mean Ξ» is zero with probability e^(βˆ’Ξ»), and that drops below a half exactly at Ξ» = ln 2, so set the expected matches to ln 2 and you need only 10 windows β€” a stream of 12 symbols. That is the birthday paradox with 64 birthdays instead of 365, and it is why a 50-symbol stream repeating itself is not a signal but the floor. Carry one caveat with you: neighbouring windows share 2 of their 3 symbols, so they are not the independent draws either count assumes, and the real break-even sits a symbol or so longer.

References (1)

Example problems

  • short run - Short sequence with 3-symbol windows: repeats still appear quickly.
  • medium run - Medium sequence shows that repeated motifs are normal by chance.
  • dense deja-vu - Longer sequences with bigger windows still generate deja-vu clusters.