-
Notifications
You must be signed in to change notification settings - Fork 0
/
sudoku-sat-interp.c
55 lines (46 loc) · 1.04 KB
/
sudoku-sat-interp.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
/**
* sudoku sat output interpreter.
*/
#include "sudoku-sat.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char* make_format(char* buf);
int main() {
int sudoku[N * N] = {0};
char buf[64];
scanf("%s", buf);
if (strcmp(buf, "s") != 0) {
printf("unexpected %s (not 's').", buf);
return 1;
}
scanf("%s", buf);
if (strcmp(buf, "SATISFIABLE") != 0) {
printf("output is not 'SATICEFIABLE'. (%s)", buf);
return 1;
}
while (scanf("%s", buf)) {
if (strcmp(buf, "v") != 0) {
index_t i = atoi(buf);
if (i == 0) {
break;
} else {
if (i > 0) {
predicate_t pred = predicate_from(i);
sudoku[pred.col + N * pred.row] = pred.num + 1;
}
}
}
}
const char* fmt = make_format((char[32]){0});
for (int i = 0; i != N * N; i += 1) {
printf(fmt, sudoku[i], (i + 1) % N ? ' ' : '\n');
}
return 0;
}
char* make_format(char* buf) {
sprintf(buf, "%d", N);
int width = strlen(buf);
sprintf(buf, "%%%dd%%c", width);
return buf;
}