I think RGGB is invalid as we have 4 different colors.
On Fri, Jun 10, 2011 at 10:10 AM, Harshal <hc4...@gmail.com> 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 <ecstasy.piy...@gmail.com>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 algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> 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 algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.