Spoof game: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
SqrtNegInf (talk | contribs) (Added Perl 6 example) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 391:
PLAYER 1 buys the drinks!
</pre>
=={{header|Julia}}==
Line 458 ⟶ 457:
No winner!
</pre>
=={{header|Kotlin}}==
Line 673 ⟶ 671:
My pot is: 1
My guess is: 6
You won!</pre>▼
=={{header|Perl 6}}==▼
{{trans|Perl}}▼
<lang perl6>sub query_for_integer ($prompt) { loop { ($_ = prompt "$prompt ") ~~ /^ \d+ $/ ?? return $_ !! say '(need an integer)'; } }▼
sub spoof_for_2 {▼
my ($mypot, $myguess, $yourpot, $yourguess) = 0, 0, 0, 0;▼
my $ngames = query_for_integer('How many games do you want?');▼
for 1 .. $ngames {▼
repeat {▼
$mypot = 1 + 3.rand.Int;▼
$myguess = 1 + 6.rand.Int;▼
} until $mypot+3 < $myguess;▼
say 'I have set my pot and guess.';▼
repeat {▼
$yourpot = query_for_integer('Your pot?' );▼
$yourguess = query_for_integer('Your guess?');▼
} until 0 <= $yourpot & $yourguess <= 6 and $yourpot+4 > $yourguess;▼
say "My pot is: $mypot\nMy guess is: $myguess";▼
given $mypot + $yourpot {▼
when $myguess & $yourguess { say 'Draw!' }▼
when $myguess { say 'I won!' }▼
when $yourguess { say 'You won!' }▼
default { say 'No winner!' }▼
}▼
}▼
}▼
spoof_for_2();</lang>▼
{{out}}▼
<pre>How many games do you want? 1▼
Your pot? 2▼
Your guess? 3▼
I have set my pot and guess.▼
My pot is: 1▼
My guess is: 5▼
You won!</pre>
Line 819 ⟶ 775:
pot:12, player2 buys the drinks!
</pre>
(formerly Perl 6)
▲{{trans|Perl}}
▲<lang perl6>sub query_for_integer ($prompt) { loop { ($_ = prompt "$prompt ") ~~ /^ \d+ $/ ?? return $_ !! say '(need an integer)'; } }
▲sub spoof_for_2 {
▲ my ($mypot, $myguess, $yourpot, $yourguess) = 0, 0, 0, 0;
▲ my $ngames = query_for_integer('How many games do you want?');
▲ for 1 .. $ngames {
▲ repeat {
▲ $mypot = 1 + 3.rand.Int;
▲ $myguess = 1 + 6.rand.Int;
▲ } until $mypot+3 < $myguess;
▲ say 'I have set my pot and guess.';
▲ repeat {
▲ $yourpot = query_for_integer('Your pot?' );
▲ $yourguess = query_for_integer('Your guess?');
▲ } until 0 <= $yourpot & $yourguess <= 6 and $yourpot+4 > $yourguess;
▲ say "My pot is: $mypot\nMy guess is: $myguess";
▲ given $mypot + $yourpot {
▲ when $myguess & $yourguess { say 'Draw!' }
▲ when $myguess { say 'I won!' }
▲ when $yourguess { say 'You won!' }
▲ default { say 'No winner!' }
▲ }
▲ }
▲}
▲spoof_for_2();</lang>
▲{{out}}
▲<pre>How many games do you want? 1
▲Your pot? 2
▲Your guess? 3
▲I have set my pot and guess.
▲My pot is: 1
▲My guess is: 5
▲You won!</pre>
=={{header|REXX}}==
|