OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [tst/] [8q.c] - Blame information for rev 72

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
int up[15], down[15], rows[8], x[8];
2
int queens(), print();
3
 
4
main()
5
{
6
        int i;
7
 
8
        for (i = 0; i < 15; i++)
9
                up[i] = down[i] = 1;
10
        for (i = 0; i < 8; i++)
11
                rows[i] = 1;
12
        queens(0);
13
        return 0;
14
}
15
 
16
queens(c)
17
{
18
        int r;
19
 
20
        for (r = 0; r < 8; r++)
21
                if (rows[r] && up[r-c+7] && down[r+c]) {
22
                        rows[r] = up[r-c+7] = down[r+c] = 0;
23
                        x[c] = r;
24
                        if (c == 7)
25
                                print();
26
                        else
27
                                queens(c + 1);
28
                        rows[r] = up[r-c+7] = down[r+c] = 1;
29
                }
30
}
31
 
32
print()
33
{
34
        int k;
35
 
36
        for (k = 0; k < 8; k++)
37
                printf("%c ", x[k]+'1');
38
        printf("\n");
39
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.