Created
March 8, 2022 05:30
-
-
Save tobycmurray/29d8aa6ac30340fd36646fb6fdf8419f to your computer and use it in GitHub Desktop.
This file contains 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
enum answer { | |
GREY, | |
YELLOW, | |
GREEN | |
}; | |
typedef enum answer ans; | |
int choose_ct(int c, int a, int b) | |
{ | |
return ((c * a) + ((1 - c) * b)); | |
} | |
int ccontains(char *word, char *guess, int n, char c) | |
{ | |
if (n > 0){ | |
int b = ccontains(word+1,guess+1,n-1,c); | |
int d = choose_ct((word[0] == guess[0]), 0, (c == word[0])); | |
int c = choose_ct(d,1,b); | |
return c; | |
}else{ | |
return 0; | |
} | |
} | |
void do_guess(char *word, char *guess, ans *out, int n) | |
{ | |
int i=0; | |
while (i < n) | |
{ | |
char g = guess[i]; | |
int eq = (g == word[i]); | |
int ot = choose_ct(eq,GREEN,choose_ct(ccontains(word,guess,n,g),YELLOW,GREY)); | |
out[i] = ot; | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment