Penney's game: Difference between revisions

Added Quackery.
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(Added Quackery.)
Line 3,116:
You win!
>>> </pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ 2 random iff char H else char T ] is flip ( --> c )
 
[ 3 times flip join join ] is randstart ( --> $ )
 
[ -1 split drop
dup -1 peek
char T = iff char H else char T
swap join ] is beststart ( $ --> $ )
 
[ stack ] is playergoal ( --> s )
[ stack ] is computergoal ( --> s )
 
[ say "This is Penney's game."
cr cr
say "We each guess a different "
say "sequence of three coin "
say "flips."
cr
say "I will releatedly flip "
say "a coin until one of the "
say "sequences happens."
cr
say "The winner is the one who "
say "guesses the sequence that "
say "happens first."
cr cr
say "Please enter your sequence "
say "carefully as there is no "
say "error checking."
cr
say 'For example, for "heads '
say 'tails heads" type "HTH".'
cr cr ] is intro ( --> )
 
[ intro
randomise
flip char H = iff
[ say "I start. My guess is: "
randstart dup echo$
computergoal put
cr
$ "Please enter your guess: "
input playergoal put ]
else
[ say "You start. "
$ "Please enter your guess: "
input dup playergoal put
beststart dup
say "I guess: " echo$
computergoal put ]
cr
$ ""
[ flip join
dup -3 split nip dup
computergoal share = iff
[ drop say "I win." ] done
playergoal share = iff
[ say "You win." ] done
again ]
cr
say "The complete sequence was: "
echo$ cr
computergoal release
playergoal release ] is play ( --> )
</syntaxhighlight>
 
{{out}}
As a dialogue in the Quackery shell (REPL).
 
<pre>/O> play
...
This is Penney's game.
 
We each guess a different sequence of three coin flips.
I will releatedly flip a coin until one of the sequences happens.
The winner is the one who guesses the sequence that happens first.
 
Please enter your sequence carefully as there is no error checking.
For example, for "heads tails heads" type "HTH".
 
You start. Please enter your guess: HTT
I guess: HHT
I win.
The complete sequence was: HTHTHHHT
 
Stack empty.
 
/O> play
...
This is Penney's game.
 
We each guess a different sequence of three coin flips.
I will releatedly flip a coin until one of the sequences happens.
The winner is the one who guesses the sequence that happens first.
 
Please enter your sequence carefully as there is no error checking.
For example, for "heads tails heads" type "HTH".
 
I start. My guess is: THT
Please enter your guess: HTH
 
I win.
The complete sequence was: TTTTTHT
 
Stack empty.
 
/O></pre>
 
=={{header|R}}==
1,462

edits