no mul->shl as it confuses address matching
[qbe.git] / minic / test / queen.c
blob7185321b9905efa76aa9ecff339c9bbc524d399c
1 int printf();
2 void *calloc();
3 int atoi();
5 int Q;
6 int N;
7 int **t;
9 print() {
10 int x;
11 int y;
13 for (y=0; y<Q; y++) {
14 for (x=0; x<Q; x++)
15 if (t[x][y])
16 printf(" Q");
17 else
18 printf(" .");
19 printf("\n");
21 printf("\n");
24 chk(int x, int y) {
25 int i;
26 int r;
28 for (r=i=0; i<Q; i++) {
29 r = r + t[x][i];
30 r = r + t[i][y];
31 if (x+i < Q & y+i < Q)
32 r = r + t[x+i][y+i];
33 if (x+i < Q & y-i >= 0)
34 r = r + t[x+i][y-i];
35 if (x-i >= 0 & y+i < Q)
36 r = r + t[x-i][y+i];
37 if (x-i >= 0 & y-i >= 0)
38 r = r + t[x-i][y-i];
40 return r;
43 go(int y) {
44 int x;
46 if (y == Q) {
47 print();
48 N++;
49 return 0;
51 for (x=0; x<Q; x++)
52 if (chk(x, y) == 0) {
53 t[x][y]++;
54 go(y+1);
55 t[x][y]--;
59 main(int ac, void **av) {
60 int i;
62 Q = 8;
63 if (ac >= 2)
64 Q = atoi(av[1]);
65 t = calloc(Q, sizeof(int *));
66 for (i=0; i<Q; i++)
67 t[i] = calloc(Q, sizeof(int));
68 go(0);
69 printf("found %d solutions\n", N);