-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveSolution.c
57 lines (48 loc) · 1.17 KB
/
saveSolution.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "saveSolution.h"
/*
for custom exact cover:
modify/replace this function with your own
and make your own print fucntions to translate and
display the set of rows in the solutions found
*/
int saveSolution_Sudoku(Dance *d)
{
SolTree *cur;
int num, igrid, rowNum, xy = d->s->xy, *grid = d->s->grid;
if(d->numSols > 1)
return d->numSols;
else if(d->numSols == 0)
return 0;
for(cur = d->sols[0]; cur->parent != cur; cur = cur->parent)
{
rowNum = cur->row->drow;
num = rowNum % xy;
igrid = rowNum / xy;
grid[igrid] = num + 1;
}
return 0;
}
/*
this pairs with initMatrixFileSudoku2()
*/
int saveSolution_Sudoku2(Dance *d)
{
SolTree *cur;
int num, igrid, xy = d->s->xy, *grid = d->s->grid;
Doubly *hrow, *xrow;
if(d->numSols > 1)
return d->numSols;
else if(d->numSols == 0)
return 0;
for(cur = d->sols[0]; cur->parent != cur; cur = cur->parent)
{
hrow = cur->row;
num = hrow->drow % xy;
for(xrow = hrow->right->right; xrow != hrow; xrow = xrow->right)
{
igrid = xrow->dcol - xy;
grid[igrid] = num + 1;
}
}
return 0;
}