八皇后
const queen =[];
var count=0;
const s=[];
for(let i=0;i<8;i++)
{
queen[i]=[];
s[i]=0
for(let j =0;j<8;j++)
{
queen[i][j]=0;
}
}
console.log(queen)
console.log(s)
for(let i =0;i<8;i++)
{
queen[0][i]=1;
s[i]=1;
search(1)
queen[0][i]=0;
s[i]=0;
}
function search(n){
for(let i =0 ;i<8;i++)
{
console.log(queen[n-1][i-1<0?0:i-1],queen[n-1][i+1>=8?7:i+1],s[i])
if(queen[n-1][i-1<0?0:i-1]==0&&queen[n-1][i+1>=8?7:i+1]==0&&s[i]==0)
{
s[i]=1;
queen[n][i]=1;
if(n==7)
{
//console.log(i)
//console.log(queen);
count++;
s[i]=0;
queen[n][i]=0
return;
}
search(n+1)
s[i]=0;
queen[n][i]=0
}
}
}
console.log(count);