Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem Set: Let's place a marker on the circle numbered 1 in the grid below. Then we will toss a coin. If the coin toss
Problem Set: Let's place a marker on the circle numbered 1 in the grid below. Then we will toss a coin. If the coin toss resulted in a 'heads', we would move the marker along the path labeled 'H' to the circle numbered 5. If the coin toss resulted in a ( 1 tails', we would move the marker along the path labeled T' to the circle numbered 4. Now we would toss the coin again and move the marker accordingly. This is repeated for any number of coin tosses. The purpose of this problem is to simulate this automata and to report the number of the circle on which the marker ends after a series of coin tosses. The marker always begins on the circle numbered 1. 2. 7 Input: Your program should accept a string consisting only of the characters 'h' or 't, where each character represents the outcome of a coin toss ('h'- heads, 't-tails). The string is terminated by a"#"character. Each character of the string triggers a move of the marker according to the rules above. A suitable prompt for the entry of this string would be 'Enter tosses: "Your program should continue to prompt strings until a 'q' is entered for the string. At this point, your program should terminate without any further output. Output For each input when the string terminator is reached, output a line of the form show below, where X is the number of the circle the marker ends up on. The marker ends on circle X Example Execution: Enter tosses: hhhtthththtttthht# The marker ends on circle 3 Enter tosses: hththththt# The marker ends on circle 6 Enter tosses
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started