-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudoku-sat.h
37 lines (31 loc) · 839 Bytes
/
sudoku-sat.h
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
#ifndef SUDOKU_SAT_H_
#define SUDOKU_SAT_H_
#ifndef N
/** THE WIDTH OF SUDOKU PROBLEM */
#define N 9
#endif
/** The type of variable index */
typedef int index_t;
/**
* Specified number placed at the column of the row
*
* means "the specified `number` is placed at the `column` of the `row`."
* note: each field start with 0.
*/
typedef struct predicate predicate_t;
struct predicate {
int row;
int col;
int num;
};
/** Get the predicate from respective index */
static inline predicate_t predicate_from(index_t index) {
return (predicate_t){.col = (index - 1) % N,
.row = (index - 1) / N % N,
.num = (index - 1) / N / N % N};
}
/** Calculate the variable index */
static inline index_t index_of(const predicate_t p) {
return 1 + p.col + N * (p.row + N * p.num);
}
#endif