Skip to content

Instantly share code, notes, and snippets.

@planetguru
Created May 1, 2015 22:19
Show Gist options
  • Save planetguru/a62356b38ffdf74ddea2 to your computer and use it in GitHub Desktop.
Save planetguru/a62356b38ffdf74ddea2 to your computer and use it in GitHub Desktop.
Mastermind solver
#include <stdlib.h>
#include <stdio.h>
int * score( int[], int[] );
int main( void ){
int result[2];
int codeword[4] = {2,2,2,3};
int testword[4] = {3,3,1,2};
result[2] = solve(codeword, testword);
printf("\nB: %d, W: %d\n",result[0],result[1]);
return 1;
}
int * solve( int testword[], int codeword[]){
int * hint[2]={0,0};
int i;
for( i=0; i < 4; i++ ){
if(testword[i] == codedword[i]){
hint[0]++;
}
}
for( i=0; i < testword.length, i!=j; i++ ){
if(testword[i]==codedword[i]){
hint[1]++;
}
}
return * hint;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment