Skip to content

Commit

Permalink
bugfix: permutation engine skipping over words
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-cooper committed Nov 29, 2016
1 parent e4ee9bd commit bbbdd41
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions scrabble.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ char *word_subset(char *letters, int *combination) {
return result;
}

int decrement(int *combination, int length) {
int decrement(int *combination, int length, int *resetter) {
int i;
int ret=1;
for (i=length-1; i >= 0; i--) {
if (combination[i] == 0) {
combination[i] = 1;
combination[i] = resetter[i];
} else {
combination[i] -= 1;
ret = 0;
Expand All @@ -215,21 +215,29 @@ int decrement(int *combination, int length) {
void scrabbler(treapset *word_set, char *letters) {
int length;
int *combination;
int *resetter;
int stop=0;

combination = create_combo_array(letters, &length);
resetter = (int *) emalloc(sizeof(int) * length);

/* copying array combinations max values */
for (int i=0; i < length; i++) {
resetter[i] = combination[i];
}

char *word;
while (stop == 0) {
word = word_subset(letters, combination);
word_searcher(word_set, word);
free(word);
stop = decrement(combination, length);
stop = decrement(combination, length, resetter);
}
sort_words(output);
destroy_treap(output, 0);
output = NULL;
free(combination);
free(resetter);

}

Expand Down

0 comments on commit bbbdd41

Please sign in to comment.