Write an interactive program or function which allows the user to play The Coinflip Game! The object of the game is to repeatedly flip a coin until you get the same result \$n\$ times in a row.
Specific behavior of the program/function is as follows:
- At the start of the game, the user inputs a positive integer \$n>1\$
- The program should then "flip a coin" (i.e. choose between two values randomly), and show the result to the user. Possible outcomes can be any two distinct outputs (e.g. 1 or 0) and must be chosen non deterministically such that each result always has a nonzero chance of appearing.
- Next, the following loop occurs
- Prompt the user to input whether they wish to continue trying or quit. This prompt must include the two input options the player has, one corresponding to continuing, and one corresponding to quitting, clearly delimited. If they choose to quit, take no further input and exit the program.
- If they choose to continue, perform another "coinflip", and show the user the outcome (same rules as before).
- If the "coinflip" has had the same outcome \$n\$ times in a row (meaning this outcome and the previous \$n-1\$ outcomes are all equal), print a congratulatory message (any message that is not one of the coinflip values or continue/quit prompts) and exit, taking no more input.
- If the "coinflip" has not had the same outcome \$n\$ times in a row yet, return to step 1 of the loop.
This is code-golf, so shortest implementation in bytes wins.
More rule clarifications:
- Steps must occur in the order shown, so you can't prompt the user to continue before showing them their first coinflip result for example.
- All six values listed below must be distinct from one another:
- Coinflip outcome 1
- Coinflip outcome 2
- Continue/Quit prompt
- Continue playing input
- Quit game input
- Congratulatory message
- The coinflip only needs to be nondeterministic; You don't need the randomness to be uniform per flip.
- There can only be two possible outcomes for each coinflip. A random float between 0 and 1 is not a coinflip.
- Player input can be taken in any reasonable fashion.
- You can assume the player will never give invalid input.