Penney's game: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (Revert several unexplained deletions of the phrase "Rosetta Code" from several examples) |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{task|Games}} |
{{task|Games}} |
||
[[wp:Penney's_game|Penney's game]] |
[[wp:Penney's_game|Penney's game]] is a game where two players bet on being the first to see a particular sequence of [[wp:Coin_flipping|heads or tails]] in consecutive tosses of a [[wp:Fair_coin|fair coin]]. |
||
It is common to agree on a sequence length of three then one player will openly choose a sequence, for example: |
It is common to agree on a sequence length of three then one player will openly choose a sequence, for example: |
||
Heads, Tails, Heads, |
Heads, Tails, Heads, or '''HTH''' for short. |
||
⚫ | |||
'''HTH''' for short. |
|||
The other player on seeing the first players choice will choose his sequence. |
|||
⚫ | |||
;Example: |
;Example: |
||
One player might choose the sequence |
One player might choose the sequence '''HHT''' and the other '''THT'''. |
||
Successive coin tosses of |
Successive coin tosses of '''HTTHT''' gives the win to the second player as the last three coin tosses are his sequence. |
||
;Task |
;Task |
||
Create a program that tosses the coin, keeps score and plays Penney's game against a human opponent. |
Create a program that tosses the coin, keeps score and plays Penney's game against a human opponent. |
||
* Who chooses and shows their sequence of three should be chosen randomly. |
|||
* If going first, the computer should randomly choose its sequence of three. |
|||
* If going second, the computer should automatically play [[wp:Penney's_game#Analysis_of_the_three-bit_game|the optimum sequence]]. |
|||
* Successive coin tosses should be shown. |
|||
<br> |
<br> |
||
Line 28: | Line 25: | ||
;See also |
;See also |
||
* |
* [https://www.youtube.com/watch?v=OcYnlSenF04 The Penney Ante Part 1] (Video). |
||
* |
* [https://www.youtube.com/watch?v=U9wak7g5yQA The Penney Ante Part 2] (Video). |
||
<br><br> |
<br><br> |
||