Penney's game: Difference between revisions

m (added two links (in the game's definition).)
Line 1,835:
HHHT
I win!</pre>
 
=={{header|zkl}}==
<lang zkl>fcn coinToss{ (0).random(2) and "H" or "T" } // (0).random(2) --> 0<=r<2
reg myBet, yourBet;
if(coinToss()=="H"){ // The toss says I go first
myBet=(3).pump(String,coinToss);
println("I bet ",myBet);
yourBet=ask("Your bet of three (H/T): ")[0,3].toUpper();
}else{
yourBet=ask("Your bet of three (H/T): ")[0,3].toUpper();
myBet=((yourBet[1]=="H") and "T" or "H") + yourBet[0,2];
println("I bet ",myBet);
}
print("Flipping: "); coins:="";
while(1){
print(toss:=coinToss()); coins=coins + toss;
if(Void!=coins.find(yourBet)){ println(" You win!"); break; }
if(Void!=coins.find(myBet)) { println(" I win!"); break; }
// ignore we both won
}</lang>
{{out}}
<pre>
$ zkl bbb
Your bet of three (H/T): tth
I bet HTT
Flipping: HHHHHHTHHTHHHTHTHHHTHTHTT I win!
 
$ zkl bbb
I bet THT
Your bet of three (H/T): hhh
Flipping: THHH You win!
</pre>
Anonymous user