Created
May 10, 2016 18:06
-
-
Save pluralism/f434e4691dbfead44cacad99b9ce914d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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