Heads Tails Heads – probability problem


  1. Write a problem to simulate the tossing of a sequence of successive coin tosses.
  1. Search the suitably generated sequence to find a particular pattern, e.g., HTH. Report where this sequence was found – after how many flips in the generated sequence. Allow the user to enter the pattern to look for via the UI (User Interface).
  1. Modify your program to repeat steps 1 and 2 a variable number of times; allow the user to specify this value in the UI. Each repeat should use the same search pattern, but a new sequence of source coin tosses.
  1. Modify your program to keep track of where the pattern was found in each generated sequence. Report the overall average number of coin tosses required to the find the search pattern across all of the repeats.
  1. If your program is correct, you will find that the average number of tosses necessary to find the search pattern HTH is 10, however, HTT it is 8. Why is this (this is another conditional probability problem)?