Git Product home page Git Product logo

nqueen's Introduction

nqueen

This is demo project for solution to N-Queen problem.

Building the JAR

To build this project, just clone the repository and run following command.

$ nqueen % ./gradlew jar

This will create executable jar at path - "build/libs/nqueen.jar".

Running the JAR

You can run executable jar with following command.

$ java -jar build/libs/nqueen.jar N y/n p

Currently two arguments are supported.

N -> Required. which is number of Queens on N x N board. Valid values are N = 4, 5, 6,......

y/n -> Options. 'y' for finding single solution. 'n' for finding all possible solutions.

p - just 'p' to print N x N board, which meets the criteria.

NOTE: If second option is not used, the program will print list of positions for a single board or count of valid board only when all possible board is selected.

Example Board

| . | . | . | Q | . | . | . | . |

| . | . | . | . | . | . | Q | . |

| . | . | Q | . | . | . | . | . |

| . | . | . | . | . | . | . | Q |

| . | Q | . | . | . | . | . | . |

| . | . | . | . | Q | . | . | . |

| Q | . | . | . | . | . | . | . |

| . | . | . | . | . | Q | . | . |

Writing Boards to text file.

If you are going to run the program from command prompt with 'y', it will print lot of values for N > 6. Better approach is to just pipe it to text file. Example:

nqueen $ java -jar build/libs/nqueen.jar 5 y > 5.txt

nqueen % java -jar build/libs/nqueen.jar 6 y > 6.txt

nqueen % java -jar build/libs/nqueen.jar 7 y > 7.txt

nqueen % java -jar build/libs/nqueen.jar 8 y > 8.txt

Then you can view all possible board combination in text file using your favorite text editor.

Performance

nqueen % time java -jar build/libs/nqueen.jar 4 y > 4.txt

0.09s user 0.03s system 125% cpu 0.097 total

nqueen % time java -jar build/libs/nqueen.jar 5 y > 5.txt

0.15s user 0.03s system 150% cpu 0.123 total

nqueen % time java -jar build/libs/nqueen.jar 6 y > 6.txt

0.27s user 0.04s system 184% cpu 0.169 total

nqueen % time java -jar build/libs/nqueen.jar 7 y > 7.txt

1.98s user 0.12s system 177% cpu 1.183 total

nqueen % time java -jar build/libs/nqueen.jar 8 y > 8.txt

27.93s user 0.19s system 102% cpu 27.555 total

nqueen % time java -jar build/libs/nqueen.jar 9 y > 9.txt

1133.09s user 3.54s system 100% cpu 18:51.88 total

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.