Skip to content

Instantly share code, notes, and snippets.

@pluralism
Created May 10, 2016 18:06
Show Gist options
  • Select an option

  • Save pluralism/f434e4691dbfead44cacad99b9ce914d to your computer and use it in GitHub Desktop.

Select an option

Save pluralism/f434e4691dbfead44cacad99b9ce914d to your computer and use it in GitHub Desktop.
char* getHint(char* secret, char* guess) {
int lenght = strlen(secret);
if(lenght != strlen(guess))
return NULL;
unsigned int x = 0,y = 0;
int cow = 0,bull = 0;
bool* val = (bool*)calloc(false, lenght * sizeof(bool));
while(x < lenght){
if(guess[x] == secret[x])
bull++;
else{
y = 0;
while(y < lenght){
if(guess[y] == secret[x] && val[y] == false){
val[y] = true;
cow++;
break;
}
y++;
}
}
x++;
}
char* res = (char*)malloc(200 * sizeof(char));
sprintf(res, "%dA%dB\0", bull, cow);
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment