Penney's game: Difference between revisions
Content added Content deleted
(Added Prolog Implementation) |
(added MiniScript example) |
||
Line 1,599: | Line 1,599: | ||
>Exit code: 0 |
>Exit code: 0 |
||
</pre> |
</pre> |
||
=={{header|MiniScript}}== |
|||
<lang MiniScript>randomTorH = function() |
|||
if rnd < 0.5 then return "T" else return "H" |
|||
end function |
|||
if rnd < 0.5 then |
|||
playerSeq = input("Input your sequence (e.g. HTH): ").upper |
|||
if playerSeq[1] == "T" then compSeq = "H" else compSeq = "T" |
|||
compSeq = compSeq + playerSeq[:2] |
|||
print "I choose: " + compSeq |
|||
else |
|||
compSeq = randomTorH + randomTorH + randomTorH |
|||
print "I choose: " + compSeq |
|||
playerSeq = input("Input your sequence (e.g. HTH): ").upper |
|||
end if |
|||
print "Here we go..." |
|||
seq = "" |
|||
while true |
|||
flip = randomTorH |
|||
print flip |
|||
seq = seq + flip |
|||
if seq[-3:] == playerSeq then |
|||
print "You win!" |
|||
break |
|||
else if seq[-3:] == compSeq then |
|||
print "I win!" |
|||
break |
|||
end if |
|||
wait |
|||
end while</lang> |
|||
{{out}} |
|||
<pre>Input your sequence (e.g. HTH): HTH |
|||
I choose: HHT |
|||
Here we go... |
|||
T |
|||
H |
|||
T |
|||
H |
|||
You win!</pre> |
|||
<pre>I choose: TTH |
|||
Input your sequence (e.g. HTH): |
|||
THH |
|||
Here we go... |
|||
H |
|||
T |
|||
T |
|||
T |
|||
T |
|||
H |
|||
I win!</pre> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |