ediloaz / N-queens-problem-HASKELL

The N-queens problem is to place n queens on a n × n board such that no queen is attacking any other queen.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

N-queens problem solved in Haskell

This program was created as part of an evaluation of a bachelor course in engineering. Resolves the N-queens problem that basicaly is is to place n queens on a n × n board such that no queen is attacking any other queen. So that no queen is attacked it is required that no queen be in the same row, neither in the same column, nor in the same diagonal.

For example, the following image solves a problem of 8 queens. Note that no queen is attacking others:

Example of 8-queens problem

Input

The program only receive a parameter as input, the N. On windows you must open GHCI (consulting prerequisites) and on Linux you must open terminal and press ghci.

When GHCI is running you need write the following commands:

Prelude> :cd C:/codes/
Prelude> :load "haskell.hs"
Main> :run main
N:

In this point the user must define the parameter N. In the terminal on Linux it looks like this:

Screenshot of an input

Output

Is shown from the terminal (or from GHCI on windows), and an example of 4 queens it looks like this:

Screenshot of an output

The approximate times of this program running (calculations and prints) on a conventional computer are close to those shown in the following table:

N miliseconds
N=5 292
N=6 356
N=7 417
N=8 819
N=9 3481

In a smooth line chart:

Screenshot of an output

Prerequisites

Steps to install haskell on Linux

  1. Install haskell from terminal with the command:
sudo apt-get install haskell-platform
  1. Install GHC (Glasgow Haskell Compiler) on GHC for linux

Steps to install haskell on Windows

  1. Install GHC (Glasgow Haskell Compiler) on GHC for windows

Running

Is necessary Glasgow Haskell Compiler, is both an interpreter and native-code compiler that runs on most platforms. In input was showed how running.

Built With

Authors

  • Edisson López - Main developer - ediloaz

See also the list of repositories who I participated/created.

About

The N-queens problem is to place n queens on a n × n board such that no queen is attacking any other queen.

License:MIT License


Languages

Language:Haskell 100.0%