Code Monkey home page Code Monkey logo

nqueens's Introduction

nqueens.py

Calculates count of solutions for N-Queen problem.

Queen

General information

N-Queen problem - you need N chess queens on a chess board with dimensions NxN in a way that they do not threat each other (according to chess rules).

Program can find all possible solutions for N-dimensional board. Also, program able to print available solutions to console or to the file.

Usage

Command line keys

Options:
  -h, --help            show this help message and exit
  -d DIMENSIONS, --dimensions=DIMENSIONS
                        Dimensions for chess board
  -p, --printsolutions  Prints solutions

By default program will calculate solutions count for 8 dimensional board and will not print solutions.

Usage

With solutions on the screen

Calculate solution for 4 dimension board and print to console:

$ nqueens.py -p -d 4

You will got something like this:

2017-04-18 20:46:20,629 - DEBUG - solver initialized for chessboard size: 4
2017-04-18 20:46:20,630 - INFO - solution:
_ _ Q _
Q _ _ _
_ _ _ Q
_ Q _ _
2017-04-18 20:46:20,633 - INFO - solution:
_ Q _ _
_ _ _ Q
Q _ _ _
_ _ Q _
2017-04-18 20:46:20,635 - INFO - solutions search complete, found solutions coun
t: 2
2017-04-18 20:46:20,636 - INFO - total solutions count - 2
2017-04-18 20:46:20,637 - INFO - done at 0.01s
Done

Where:

_ _ Q _
Q _ _ _
_ _ _ Q
_ Q _ _

one of possible solutions.

Calculating solutions count

When you need just count solutions count, you can execute nqueens using:

$ nqueens.py -d 8

You will get someting like this

2017-04-18 20:47:49,566 - DEBUG - solver initialized for chessboard size: 8
2017-04-18 20:47:49,605 - INFO - solutions search complete, found solutions count: 92
2017-04-18 20:47:49,606 - INFO - total solutions count - 92
2017-04-18 20:47:49,607 - INFO - done at 0.04s

So, total solutions count for 8-dimensional board is 92.

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.