Problem solved in full
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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)
- Insight block 3 β why AAAA clumps and ABCD does not: L. J. Guibas and A. M. Odlyzko, "String overlaps, pattern matching, and nontransitive games." Journal of Combinatorial Theory, Series A 30(2), 183β208, 1981 β the correlation polynomial that measures how a pattern overlaps a shifted copy of itself.