**Your task is to create a
sequence that is unexpected.**
You will probably find this a very difficult thing to do.

What does *unexpected* mean? The code considers the last few
tosses in the current sequence and sees if that sequence has occurred
before. If so it predicts that you will click on the same button as
you did the last time. The size of the last subsequence is is as
large as possible, but no larger than the number listed in the second text field of the control panel.
The maximum possible value of is 15.
A smaller value may be more effective, and you may want to
pick a very small value, like for experimental purposes.
Regardless of your choice of , the system keeps track of your key
clicks for all subsequences of length up to . Thus you can
change as you go along, and if you increase its value past
information will already be present.

If no past information is available, for example before your first choice of Heads or Tails, the system guesses that you'll choose Heads. So you'll get off to a good start by clicking on TAILS.

The large text field in the control panel lists the current score, for example:

The smiley face indicates that the computer guessed wrong at the
last toss, there have been a total of 10 tosses, in 4 cases the
computer guessed right, and in 6 it guessed wrong. The *score* is
the difference between the player's score and the mean (half the
number of guesses), divided by the standard deviation. A
positive score means the player is ahead, a negative the opposite.
If the score exceeds the text field turns green, if it is less
than it turns red. These color changes can be
construed as a win by the player or computer, respectively. It is
unlikely that a deviation from the mean by three standard deviations
is by chance.

The reset button resets the computer memory and lets you start over. Clicking on the applet or the Quit Button exists the code.

You can see the computer's upcoming guess by clicking on
**Next**. Let
be the number in the text field to the right of that button. If
the computer's guess is printed to standard output. It is
also indicated in the title of the control panel. If the next
optimal player tosses are applied and listed to standard output.

The behavior of the computer is entirely deterministic and thus it is possible, by careful bookkeeping, to obtain a perfect score against it. The following table lists the beginning of the optimal sequence of tosses (with that give rise to that score.

Toss | Computer | Player | Why? |

1 | H | T | Initial computer guess H, no history. Player plays T. |

2 | H | T | past history is T, never occurred before. |

3 | T | H | toss 2 was T after T, computer guess will be T again, player plays H |

4 | H | T | past history is H, never occurred before. |

5 | H | T | toss 3 was H after T, guess will be H again. |

6 | H | T | toss 3 was H after TT, guess will be H again. |

7 | T | H | toss 6 was T after TT, guess will be T again. |

8 | T | H | toss 4 was T after TTH, guess will be T again. |

9 | H | T | toss 8 was H after H. |

10 | T | H | toss 9 was T after H. |

11 | H | T | toss 8 was H after TH. |

12 | T | H | toss 5 was T after THT. |

13 | T | H | toss 11 was T after HTH. |

14 | T | H | toss 9 was T after THH. |

15 | H | T | toss 14 was H after HH. |

16 | H | T | toss 10 was H after HHT. |

17 | T | H | toss 6 was T after HTT. |

18 | H | T | toss 8 was H after TTH. |

19 | T | H | toss 5 was T after TTHT. |

20 | H | T | toss 14 was H after THTH. |

The first 1000 tosses in the optimal sequence (given above in ** red letters ) are:
**

T | T | H | T | T | T | H | H | T | H | T | H | H | H | T | T | H | T | H | T | T | H | H | H | H | T | H | H | T | T | T | T | H | T | T | H | T | T | T | T | T | H | H | H | T | H | T | T | T | H |

T | H | H | T | H | H | H | H | H | T | T | T | H | H | H | H | H | H | T | H | T | H | T | H | H | T | T | H | H | T | T | T | H | T | T | T | H | T | T | H | H | T | H | H | T | H | T | T | H | T |

H | H | H | H | T | T | H | H | H | T | T | T | T | T | T | H | T | H | T | H | T | T | T | T | H | H | T | T | H | T | T | H | T | H | T | H | H | H | H | H | H | H | T | T | H | T | T | T | H | H |

H | T | T | H | H | T | H | T | T | T | T | T | T | T | H | H | T | H | H | H | T | H | H | H | H | T | H | T | T | H | H | T | T | H | H | H | H | H | T | H | H | H | T | T | T | H | T | H | T | T |

T | H | H | T | T | T | T | T | H | T | T | T | T | H | T | H | H | H | T | H | T | H | H | T | H | T | H | T | T | H | T | T | H | H | H | T | H | H | T | H | H | T | T | H | T | H | H | T | T | T |

H | H | T | H | H | T | T | T | H | T | H | H | H | H | H | T | H | T | T | T | T | H | T | T | T | H | H | T | T | H | H | T | H | H | H | H | T | T | T | T | H | H | H | H | T | T | H | T | H | H |

H | T | T | T | T | H | T | H | T | T | H | T | H | T | T | T | T | T | H | T | H | H | T | T | H | T | T | T | T | H | H | H | T | T | T | H | H | T | T | T | H | H | H | T | H | H | H | T | H | T |

T | H | T | T | T | H | T | H | T | H | H | T | H | H | T | H | H | H | T | T | H | H | H | H | T | T | T | H | T | T | H | T | H | H | T | H | T | T | T | H | H | H | H | T | H | T | H | H | H | H |

T | H | H | H | H | H | H | T | T | T | T | T | H | H | T | T | T | T | H | H | T | H | T | T | H | H | H | T | T | H | T | T | H | H | T | T | T | T | T | T | T | T | H | T | T | H | H | H | H | H |

H | H | H | T | H | H | T | H | T | H | H | T | T | T | T | T | H | H | H | H | H | T | T | H | H | T | T | H | T | H | T | H | T | H | T | T | H | H | T | H | T | H | T | H | T | H | H | H | T | H |

H | T | T | H | H | H | T | H | T | H | T | T | T | H | T | T | T | T | T | T | H | H | H | T | T | H | T | H | H | T | H | H | T | T | T | T | T | T | H | H | T | T | H | H | H | T | T | H | H | H |

T | H | H | H | H | H | T | H | H | T | T | H | T | T | H | H | H | H | T | T | H | H | T | H | H | T | T | H | H | T | H | T | H | H | T | H | H | H | T | H | T | H | T | H | T | T | T | H | H | H |

T | H | T | H | H | H | T | H | T | T | T | T | T | H | H | T | H | T | H | T | T | T | T | T | T | H | T | T | T | H | T | H | H | H | T | T | H | H | T | T | T | T | H | T | H | H | T | H | T | H |

H | H | H | H | T | T | H | T | H | T | H | H | T | T | T | H | T | T | H | H | H | T | T | T | H | T | T | T | T | H | H | T | H | H | T | H | H | T | H | T | H | T | H | H | H | H | T | T | T | H |

H | T | H | T | T | T | H | T | T | H | T | T | H | T | T | T | H | H | T | H | H | H | H | H | H | H | H | H | T | T | T | H | T | H | H | T | T | T | T | H | H | H | T | H | H | T | T | T | H | H |

H | H | T | T | T | T | T | T | T | H | T | H | H | H | H | T | H | T | H | T | T | H | H | H | T | H | T | T | H | H | H | H | H | T | T | T | T | H | T | T | T | T | T | H | T | T | H | T | H | T |

T | H | T | T | T | T | H | T | T | H | H | T | T | H | T | T | T | H | T | T | T | H | H | H | H | H | T | H | T | H | H | T | T | H | T | H | T | T | T | H | T | H | T | T | H | H | T | T | T | H |

H | T | T | H | T | H | H | H | H | H | H | T | H | H | H | H | T | T | H | T | T | H | T | T | H | H | T | H | T | T | H | T | T | H | T | H | H | H | T | H | H | H | T | T | H | T | T | T | T | T |

T | T | T | T | H | H | H | H | T | H | H | H | T | H | H | T | H | T | T | T | T | H | H | H | H | H | H | H | T | H | T | T | H | T | H | T | H | T | T | H | T | H | H | T | T | H | H | H | H | T |

H | T | T | T | H | H | T | H | T | T | H | T | H | T | T | H | H | T | H | H | H | T | T | T | T | T | H | T | H | T | T | T | T | H | T | H | T | H | H | H | T | T | T | H | H | H | T | T | T | T |

Of course, the challenge is to win against the code unaided, depending only on your memory and intuition. On the other hand, you don't have to get a perfect score, just work your way up to three standard deviations. Good luck!

m |
repeating part |

1 | T T H H |

2 | T T T H H H T H |

3 | T T T T H H T H T H H H H T T H |

4 | T T T T T H T T T H H T H T H H H T T H T H T T H H H H H T H H |

If you set the value of accordingly and keep entering
the above mentioned sequence of tosses you will win. There is an
obvious structure in those sequences that you may want to investigate.
If one starts some way, and then plays optimally, the sequences of
tosses will become periodic. Let's define a *winning period* to be a sequence of coin tosses which is such that if we start with it, and keep repeating it, eventually the computer will cease scoring at all.
(Of course a winning period depends on
.)
Here are some possible questions to ask:

- Are there other winning periods?
- Are there winning periods of length different from
*2*?^{m+1} - If not, for a given what are the lengths of the shortest and longest winning periods?