#include<stdio.h>
int *calc(char *sol,char *guess)
{
int chk[4]={0,0,0.0};
int i,j;
for(i=0;i<4;i++)
{
if(sol[i]==guess[i])
{
chk[i]=2;
}
}
for(i=0;i<4;i++)
{
if(chk[i]!=2)
{
for(j=0;j<4;j++)
{
if(chk[j]!=2)
{
if(guess[i]==sol[j])
chk[i]=1;
}
}
}
}
return chk;
}
main()
{
int *p=calc("RGGB","BGGR");
int count_ps=0,count_h=0;
int i=0;
while(i<4)
{
if(*p==1)
count_ps++;
else if(*p==2)
count_h++;
i++;
p++;
}
printf("no. of hits =%d\n",count_h);
printf("no. of pseudohits =%d\n",count_ps);
return 0;
}
On Fri, Jun 10, 2011 at 10:14 AM, Ashim Kapoor <[email protected]>wrote:
>
> I think RGGB is invalid as we have 4 different colors.
>
>
>
> On Fri, Jun 10, 2011 at 10:10 AM, Harshal <[email protected]> wrote:
>
>>
>> #include<iostream>
>> #include<string>
>>
>> using namespace std;
>>
>> void mastermind(char* guess, char* sol, int *hits, int *pseudohits)
>> {
>> int temp[256] = {0};
>> int len1=strlen(sol);
>> int len2=strlen(guess);
>>
>> while(--len1+1)
>> (guess[len1]==sol[len1]) ? ((*hits)+=1,temp[len1] = 1) :
>> (temp[sol[len1]] += 1);
>>
>> while(--len2+1)
>> if(temp[len2]!=1 && temp[guess[len2]] > 0)
>> (*pseudohits)++, temp[guess[len2]] -= 1;
>> }
>>
>> int main()
>> {
>> int hits=0,pseudo=0;
>> mastermind("RGGB","YRGB",&hits,&pseudo);
>> cout<<hits<<" "<<pseudo;
>> }
>>
>> On Fri, Jun 10, 2011 at 2:31 AM, Piyush Sinha
>> <[email protected]>wrote:
>>
>>>
>>> Game of master mind: you have four balls, and four different colors, as a
>>> solution. The user tries to guess the solution. If they guess the right
>>> color for the right spot, it counts as a 'hit'. If it's the right color, but
>>> the wrong spot, it counts as a psuedo-hit. For example: if the solution is
>>> 'RGGB' and the user guesses 'YRGB' they have 2 hits and one pseudo hit.
>>> Write a program to, given a solution and a guess, calculate the number of
>>> hits and pseudo hits.
>>> --
>>> *Piyush Sinha*
>>> *IIIT, Allahabad*
>>> *+91-8792136657*
>>> *+91-7483122727*
>>> *https://www.facebook.com/profile.php?id=100000655377926 *
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Harshal Choudhary,
>> III Year B.Tech CSE,
>> NIT Surathkal, Karnataka, India.
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.