Bulls and cows/Player: Difference between revisions

m
→‎{{header|Perl 6}}: fixed calculation of $exact, add sample output
No edit summary
m (→‎{{header|Perl 6}}: fixed calculation of $exact, add sample output)
Line 1,823:
 
=={{header|Perl 6}}==
{{works with|Rakudo|2018.0212}}
{{trans|Perl}}
 
Line 1,840:
# they are needed and saves us a lot of arguments to our two routines.
sub score-correct($a) {
my $exact = [+] $a Z>>==<< $guess;
# use the Z (zip) meta operator along with == to construct the
# list ($a[0] == $b[0], $a[1] == $b[1], ...) and then add it up
# using the reduction meta operator [] and +.
my $exact = [+] $a Z== $guess;
 
# number of elements of $a that match any element of $b
Line 1,855 ⟶ 1,852:
my $score = prompt "My guess: {$guess.join}.\n";
 
# use the :s modifier to tell Perl 6 to handle spaces
# automatically and save the first digit in $<bulls> and
# the second digit in $<cows>
if $score ~~ m:s/^ $<bulls>=(\d) $<cows>=(\d) $/
and $<bulls> + $<cows> <= 4 {
Line 1,871 ⟶ 1,865:
?? "Your secret number is {@candidates[0].join}!"
!! "I think you made a mistake with your scoring.";</lang>
{{out}}
<pre>My guess: 4235.
2 1
My guess: 1435.
2 1
My guess: 1245.
2 1
Your secret number is 1234!</pre>
 
=={{header|Phix}}==
2,392

edits