int run( FILE* fin ) { char word[64]; size_t wsize = sizeof( word ); while (fgets( word, wsize, fin )) { Seq_T solutions = Seq_new( 5 ); if (wstable_hasWord( word, solutions )) { process_solutions( solutions ); } Seq_free( &solutions ); } return 0; }
void backtrack(int dms) { int i, ncandidate, tmp; int candidates[10]; if (dms == 5) process_solutions(); else { construct_solutions(dms, candidates, &ncandidate); for (i = 0; i < ncandidate; ++i) { tmp = candidates[i]; /* solutions[] holding the ascii char */ solutions[dms] = tmp + 0x30; used[tmp] = true; backtrack(dms + 1); used[tmp] = false; } } }
void backtrack(int y, int x) { int i, ncandidate, tmp; int candidates[2]; /* (1, len), 1 unit exceed */ if (y == len && !x) process_solutions(); else if (graph[y][x] == 'X') { used_y[y] = false; used_x[x] = false; if (x == len - 1) backtrack(y + 1, 0); else backtrack(y, x + 1); } else { construct_solutions(y, x, candidates, &ncandidate); for (i = 0; i < ncandidate; ++i) { tmp = candidates[i]; graph[y][x] = tmp; /* rook */ if (tmp == '*') used_y[y] = used_x[x] = true; if (x == len - 1) backtrack(y + 1, 0); else backtrack(y, x + 1); if (tmp == '*') used_y[y] = used_x[x] = false; } } }