October 14, 2019

Solving Eight Queen problem in chess board

/**
 *

Trying to solve eight queen problem in a chess board


 */
package com.codecreeks.solutions;

/**
 * @author Consumerfed kozhikode Information Technology Section
 *
 */
public class EightQueen {

/**
* @param args
*/
public static void main(String[] args) {

int[][] output = { { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 } };

int x = 0;
int y = 0;
int queen = 1;
int queenCount = 8;

while (queen <= queenCount) {
output[x][y] = 1;
x = x + 1;
y = y + 2;
if (y >= 8) {
y = (y % 8) + 1;
}
queen++;
}

for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
System.out.print(output[row][col] + " ");
}
System.out.println();
}

}

}

Output



1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1

Chess Boards available

So you must be wondering what is the revenue of our blog ? The commission (around 1 to 2 %) from amazon when any one purchase any amazon product through this blog. so we request you to buy any amazon product through this blog.


No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments