diff --git a/C#/README.md b/C#/README.md new file mode 100644 index 0000000..9da5ed3 --- /dev/null +++ b/C#/README.md @@ -0,0 +1,42 @@ +# N-Queens problem using backtracking and CS + +## C# implementation + +### Set up (Ubuntu 22.04) + +```shell +apt install dotnet-sdk-8.0 +``` + +### Build + +```shell +dotnet build --configuration Release queens.csproj +``` + +### Syntax + +``` +queens.jar [-test] [SIZE] +``` + +
+
-test
+
Enable test output.
+
SIZE
+
Length of the chess.
+
+ +### Example + +``` +# bin/Release/net8.0/queens 1024 + +Queen 1: square 492 +Queen 2: square 294 +(...) +Queen 1023: square 612 +Queen 1024: square 498 + +Solved in 1024 steps. Time: 137 ms. +``` diff --git a/C++/Queens.sdf b/C++/Queens.sdf deleted file mode 100644 index 4d0f46a..0000000 Binary files a/C++/Queens.sdf and /dev/null differ diff --git a/C++/README.md b/C++/README.md new file mode 100644 index 0000000..31dbb67 --- /dev/null +++ b/C++/README.md @@ -0,0 +1,46 @@ +# N-Queens problem using backtracking and CS + +## C++ implementation + +### Set up (Ubuntu 22.04) + +```shell +apt install g++ make +``` + +### Build + +```shell +make +``` + +### Syntax + +``` +queens [-test] [SIZE] +``` + +
+
-test
+
Enable test output.
+
SIZE
+
Length of the chess.
+
+ +### Example + +``` +# ./queens 1024 + +Queen 1: square 492 +Queen 2: square 294 +(...) +Queen 1023: square 873 +Queen 1024: square 179 + +Steps: 19019 +Discards: 906012 +Time: 476.74 ms. +Performance: 39 steps/ms. + 1900 discards/ms. +``` diff --git a/Go/README.md b/Go/README.md new file mode 100644 index 0000000..f7039e5 --- /dev/null +++ b/Go/README.md @@ -0,0 +1,44 @@ +# N-Queens problem using backtracking and CS + +## Go implementation + +### Set up (Ubuntu 22.04) + +```shell +apt install golang +``` + +### Build + +```shell +go build +``` + +### Syntax + +``` +queens [-test] [SIZE] +``` + +
+
-test
+
Enable test output.
+
SIZE
+
Length of the chess.
+
+ +### Example + +``` +# ./queens 1024 + +[0] 338 +[1] 591 +(...) +[1022] 155 +[1023] 790 +Steps: 1051 +Discards: 750108 +Time: 43.254331ms +Performance: 24 steps/ms +``` diff --git a/JS/README.md b/JS/README.md new file mode 100644 index 0000000..20c18d3 --- /dev/null +++ b/JS/README.md @@ -0,0 +1,38 @@ +# N-Queens problem using backtracking and CS + +## JavaScript implementation + +### Set up (Ubuntu 22.04) + +```shell +apt install nodejs +``` + +### Syntax + +``` +queens.js [-h] [-test] [SIZE] +``` + +
+
-h
+
Print help.
+
-test
+
Enable test output.
+
SIZE
+
Length of the chess.
+
+ +### Example + +``` +# java -jar queens.jar 1024 + +Queen 1: square 172 +Queen 2: square 1003 +(...) +Queen 1023: square 288 +Queen 1024: square 347 + +Solved in 1020 steps. Time: 180.78 ms. +``` diff --git a/Java/README.md b/Java/README.md new file mode 100644 index 0000000..bec2767 --- /dev/null +++ b/Java/README.md @@ -0,0 +1,42 @@ +# N-Queens problem using backtracking and CS + +## Java implementation + +### Set up (Ubuntu 22.04) + +```shell +apt install openjdk-19-jdk-headless +``` + +### Build + +```shell +make +``` + +### Syntax + +``` +queens.jar [-test] [SIZE] +``` + +
+
-test
+
Enable test output.
+
SIZE
+
Length of the chess.
+
+ +### Example + +``` +# java -jar queens.jar 1024 + +Queen 1: square 492 +Queen 2: square 294 +(...) +Queen 1023: square 647 +Queen 1024: square 955 + +Solved in 1142 steps. Time: 92 ms. +``` diff --git a/PHP/README.md b/PHP/README.md new file mode 100644 index 0000000..0406910 --- /dev/null +++ b/PHP/README.md @@ -0,0 +1,35 @@ +# N-Queens problem using backtracking and CS + +## PHP implementation + +### Set up (Ubuntu 22.04) + +```shell +apt install php +``` + +### Syntax + +``` +queens.php [-test] [SIZE] +``` + +
+
-test
+
Enable test output.
+
SIZE
+
Length of the chess.
+
+ +### Example + +``` +# php queens.php 256 + +Queen 1: square 172 +Queen 2: square 1003 +(...) +Queen 255: square 45 +Queen 256: square 174 +Solved in 5106 steps. Time: 445.57 ms. +``` diff --git a/Python/README.md b/Python/README.md new file mode 100644 index 0000000..fccaf6e --- /dev/null +++ b/Python/README.md @@ -0,0 +1,35 @@ +# N-Queens problem using backtracking and CS + +## Python implementation + +### Set up (Ubuntu 22.04) + +```shell +apt install python3 +``` + +### Syntax + +``` +queens.py [-test] [SIZE] +``` + +
+
-test
+
Enable test output.
+
SIZE
+
Length of the chess.
+
+ +### Example + +``` +# ./queens.py 512 + +Queen 1: square 172 +Queen 2: square 1003 +(...) +Queen 511: square 1 +Queen 512: square 1 +Solved in 1591 steps. Time: 1241.388 ms. +``` diff --git a/README.md b/README.md new file mode 100644 index 0000000..97a0029 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# N Queens Problem Solver + +[![CI](https://github.com/vikman90/queens-psr/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/vikman90/queens-psr/actions/workflows/ci.yml) + +This is a set of implementations of the famous N Queens Problem solver in +multiple programming languages. The N Queens Problem is a problem of placing N +queens on an NxN chessboard without any queen being able to attack the others. + +## Features + +- Efficient implementations. +- Utilize backtracking and constraint propagation to find a solution. +- Provides the ability to specify the number of queens (size of the board). +- Offers an alternative testing output of the found solutions. + +## Performance comparison + +|Implementation|Steps/ms (avg)|Discards/ms (avg)| +|--|--:|--:| +|C++|125,20|10.715,92| +|Rust|93,10|5.793,85| +|Go|72,91|1.282,14| +|JavaScript|29,49|1.629,27| +|C#|22,65|1.263,75| +|Java|13,26|1.047,12| +|Python|2,17|519,03| + +## Usage + +Instructions available at each implementation folder. + +## Contribution + +Contributions are welcome! If you have any ideas to improve this project, feel free to submit a pull request. + +## Credits + +This project was developed by [Vikman Fernandez-Castro](https://github.com/vikman90). + +## License + +This project is licensed under the MIT License. diff --git a/Rust/README.md b/Rust/README.md index 73f32e4..71af58f 100644 --- a/Rust/README.md +++ b/Rust/README.md @@ -2,24 +2,31 @@ ## Rust implementation -### Set up +### Set up (Ubuntu 22.04) -```sh -yum install rustc cargo +```shell +apt install cargo +``` + +### Build + +```shell cargo build --release ``` ### Syntax ``` -queens [-h] [-p] [SIZE] +queens [-h] [-p] [-test] [SIZE] ```
-h
-
Show help.
+
Print help.
-p
Enable parallel mode.
+
-test
+
Enable test output.
SIZE
Length of the chess.
@@ -27,17 +34,16 @@ queens [-h] [-p] [SIZE] ### Example ``` -# cargo run --release -- -p 4000 +# cargo run --release -- -p 1024 -Queen 1: square 1252 -Queen 2: square 2295 +Queen 1: square 313 +Queen 2: square 3 (...) -Queen 3999: square 3509 -Queen 4000: square 1655 - -Trials: 58765 -Discards: 182326630 -Time: 4539 ms. -Performance: 0.013 steps/μs. - 40.167 discards/μs. +Queen 1023: square 776 +Queen 1024: square 549 +Trials: 12290 +Discards: 10912362 +Time: 654 ms. +Performance: 0.019 steps/μs. + 16.678 discards/μs. ```