// n queens problem
class Queen{
List<Move> list = new ArrayList<>();
private int width = 4;
public Queen(int width){
this.width = width;
}
class Move{
public int c;
public int r;
public Move(int c, int r){
this.c = c;
this.r = r;
}
}
// int c = 0;
public void queenSolver(int c){
if(c == width){
for(Move m:list){
Print.p("[" + m.c + "," + m.r + "]");
}
Ut.l();
}else{
for(int r=0; r<width; r++){
if(isValidMove(c, r)){
list.add(new Move(c, r));
queenSolver(c+1);
list.remove(list.size()-1);
}
}
}
}
public boolean isValidMove(int c, int r){
for(Move m : list){
if(m.r == r || Math.abs(m.c - c) == Math.abs(m.r - r))
return false;
}
return true;
}
}