/* Copyright (c) 2007 by Bernd Breitenbach. All Rights Reserved
This is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include <stdio.h>
signed char columns[8];
void search(int colno)
{
const char hline[]="\n+-+-+-+-+-+-+-+-+\n";
int i,j,ok;
for(i=0;i<8;i++) {
ok=1;
for (j=0;j<colno;j++) {
if (i==columns[j] || abs(i-columns[j])==abs(colno-j)) {
ok=0;
break;
}
}
if (ok) {
columns[colno]=i;
if (colno==7) {
printf(hline);
for(i=0;i<8;i++) {
for (j=0;j<8;j++) {
if (j==columns[i]) {
printf("|D");
} else {
printf("| ");
}
}
printf("|%s",hline);
}
} else {
search(colno+1);
}
}
}
}
int main()
{
search(0);
return 0;
}