Bulls and cows: Difference between revisions

Content added Content deleted
(GP)
Line 1,789: Line 1,789:
in
in
{Main}</lang>
{Main}</lang>

=={{header|PARI/GP}}==
This simple implementation expects guesses in the form [a,b,c,d].
<lang parigp>bc()={
my(u,v,bulls,cows);
while(#vecsort(v=vector(4,i,random(9)+1),,8)<4,);
while(bulls<4,
u=input();
if(type(u)!="t_VEC"|#u!=4,next);
bulls=sum(i=1,4,u[i]==v[i]);
cows=sum(i=1,4,sum(j=1,4,i!=j&v[i]==u[j]));
print("You have "bulls" bulls and "cows" cows")
)
};</parigp>


=={{header|Perl}}==
=={{header|Perl}}==