Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README #5

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions C#/README.md
Original file line number Diff line number Diff line change
@@ -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]
```

<dl>
<dt>-test</dt>
<dd>Enable test output.</dd>
<dt>SIZE</dt>
<dd>Length of the chess.</dd>
</dl>

### 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.
```
Binary file removed C++/Queens.sdf
Binary file not shown.
46 changes: 46 additions & 0 deletions C++/README.md
Original file line number Diff line number Diff line change
@@ -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]
```

<dl>
<dt>-test</dt>
<dd>Enable test output.</dd>
<dt>SIZE</dt>
<dd>Length of the chess.</dd>
</dl>

### 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.
```
44 changes: 44 additions & 0 deletions Go/README.md
Original file line number Diff line number Diff line change
@@ -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]
```

<dl>
<dt>-test</dt>
<dd>Enable test output.</dd>
<dt>SIZE</dt>
<dd>Length of the chess.</dd>
</dl>

### Example

```
# ./queens 1024

[0] 338
[1] 591
(...)
[1022] 155
[1023] 790
Steps: 1051
Discards: 750108
Time: 43.254331ms
Performance: 24 steps/ms
```
38 changes: 38 additions & 0 deletions JS/README.md
Original file line number Diff line number Diff line change
@@ -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]
```

<dl>
<dt>-h</dt>
<dd>Print help.</dd>
<dt>-test</dt>
<dd>Enable test output.</dd>
<dt>SIZE</dt>
<dd>Length of the chess.</dd>
</dl>

### 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.
```
42 changes: 42 additions & 0 deletions Java/README.md
Original file line number Diff line number Diff line change
@@ -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]
```

<dl>
<dt>-test</dt>
<dd>Enable test output.</dd>
<dt>SIZE</dt>
<dd>Length of the chess.</dd>
</dl>

### 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.
```
35 changes: 35 additions & 0 deletions PHP/README.md
Original file line number Diff line number Diff line change
@@ -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]
```

<dl>
<dt>-test</dt>
<dd>Enable test output.</dd>
<dt>SIZE</dt>
<dd>Length of the chess.</dd>
</dl>

### 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.
```
35 changes: 35 additions & 0 deletions Python/README.md
Original file line number Diff line number Diff line change
@@ -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]
```

<dl>
<dt>-test</dt>
<dd>Enable test output.</dd>
<dt>SIZE</dt>
<dd>Length of the chess.</dd>
</dl>

### 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.
```
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
38 changes: 22 additions & 16 deletions Rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,48 @@

## 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]
```

<dl>
<dt>-h</dt>
<dd>Show help.</dd>
<dd>Print help.</dd>
<dt>-p</dt>
<dd>Enable parallel mode.</dd>
<dt>-test</dt>
<dd>Enable test output.</dd>
<dt>SIZE</dt>
<dd>Length of the chess.</dd>
</dl>

### 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.
```