# Questions tagged [n-queens]

The n-queens puzzle is the problem of placing n chess queens on an n×n chessboard so that no two queens can attack each other.

29 questions
82 views

### N Queens in Python using backtracking

I write this solution to the popular N Queens problem using backtracking algorithm. I am relatively new to Python. I would like to know what are the ways to refactor this code and also code style of ...
29 views

### NQueen solution in scala

This is my solution for NQueen problem in scala. I just want to know how to make it more easy to read, modular and areas i need to improve. ...
359 views

### N Queen Problem C++

Following code is solving n queen problem with c++ using backtracking. I saw other people solution they are very short like 20 to 30 lines. Is there way improve following code? ...
37 views

### N Queens on NxN board once more

I am quite new to C++ programming, and would appreciate any comments. How many combinations of N chess queens on a N×N board exist that there is no two queen attacking each other? Input <...
75 views

### Using most constraining variable and least constraining value for N-queens challenge

I was trying to solve the N-Queens(Only 1 solution) problem and I succeeded but my program could only calculate up to N = 47 in a good amount of time so I tried to implement least constraining value ...
66 views

### Codeforces: Queens, Again

code review friends/teachers! This is a trivial(no dfs/permutations/backtrace required) n queen problem from codeforces: B. 8 Queens, Again!! input 2 A1 B5 C8 D6 E3 F7 G2 H4 C3 E4 C4 E1 ...
248 views

### Find all N-Queens solution

This code is a multi-threading recursive backtracking DFS algorithm to find all solutions to the N-Queens problem. The board size is indicated by BOARD_SIZE. ...
132 views

### Parallel solutions to N Queens Puzzle

I'm trying to increase the performance of my N Queens Puzzle solution. I'd find some threads on SO already but they don't appear to help me to increase performance. My best solution, however, is a ...
211 views

### Backtracking solver for n queens problem and knight's tour

Playing with https://ocaml.org/learn/tutorials/99problems.html#Miscellaneous-Problems I wrote a backtracking solver for the n queens problem, then the knight's tour, and realised I could generalise ...
589 views

### N Queens in Python

I used Python very occasionally, today I solved n queens in Python just for fun. I am sure there are better way of doing certain things in Python and can't wait for improvement suggestions! ...
2k views

### Eight queens with Java

The following code works great but take too much time. placeQueens requires much time too. The program takes 5-10 seconds. ...
240 views

I tried to solve the N Queens problem in Haskell using backtracking. Here is my approach: ...
302 views

### N queens variation recursion Python 3

I am trying to solve a modified version of the N-queens problem, where the addition is that for any NxN board (3<=N<=12) there are M holes (0<=M<=N^2) that are placed at random (but given) ...
310 views

### Compute all valid configuration of eight queens on a 8x8 chess board

Write an algorithm to print all valid ways of arranging eight queens on an 8x8 chess board so that none of them attack any other. Following is my code for this. Do you see any performance or coding ...
104 views

### Permutation-stream based n-queens solution

Following is a very crisp solution for solving n-queens problem in Racket programming language. The method is to get all permutations (so that no 2 queens are in same line) and to check these for any ...
185 views

### Solution to N-queens problem in Racket

I am using following method to solve N-queens problem for all possible solutions for a board. It seems to be smaller as well as faster than many commonly mentioned method. Also, since it is tail-...
301 views

### Chessboard puzzle in Java

Here is the puzzle: Put il queens (a figure in chest) on the chessboard with quadratic dimensions a x ...
2k views

### N-Queens Problem in Java

I have a version of the N-Queens problem in Java. I have function that returns the column placement for each row. And another function that takes that and translates it to a board with '.' ...
491 views

### N-Queens, bitwise approach

I've recently solved the famous N-Queens problem: Can you place $N$ chess queens on a $N × N$ board in such a way that no one attacks another queen? The idea here is based on the ideas from ...
2k views

### N-Queens Recursive Implementation in C++11

I created a recursive, optimized, N-Queens implementation in CPP. Any suggestions for improvement? ...
395 views

### N-Queens challenge

I am doing an exhaustive search in N-queens code I wrote in C++. How can I optimize this code further? It takes an input n (the number of queens) and returns a <...
994 views

### n-Queens backtracking code

I was learning backtracking algorithms earlier today, and was excited and wrote this code for n-Queens problem. Being my first try at backtracking algorithms, I would appreciate if you guys could chip ...
2k views

### n-queens puzzle in Python

I want to increase the efficiency and reduce the time complexity for the n-queen problem in n*n matrix chess. I am able to run only still (11*11) in normal time otherwise for the big number it is ...
272 views

### An iterator returning all possible solutions to n-queen problem in Java - follow-up

(See the initial iteration.) Now I have slightly improved performance of the iterator. Whenever we have set a queen at a particular board cell, the previous iteration sacrifices $\mathcal{O}(n)$ ...
137 views

### An iterator returning all possible solutions to n-queen problem in Java

(See the next iteration.) Given a positive integer $n$, I have an iterator that returns all possible solutions to $n$-queens problem one by one: QueenIterableV1.java: ...
115 views

### Attack-Rooks challenge [closed]

Attack-Rooks is a challenge proposed by ACM-ICPC as a variant of the N-Queens problem, using Rooks instead of Queens. Of course, to disallow the trivial "fill the diagonal" solution, pawns are used to ...
1k views

### N-queens problem in Haskell by bruteforce

I wrote a Haskell program to solve the N-queens problem by bruteforce. It works and I find it reasonably readable But it is pretty slow: 5 seconds for one solution of 8 queens. 1 minute for one ...
Figure 2.8: A solution to the eight-queens puzzle. The eight-queens puzzle'' asks how to place eight queens on a chessboard so that no queen is in check from any other (i.e., no two ...