Code Monkey home page Code Monkey logo

nqueen's Introduction

Build Status

NQueen - Problem

Basically this is a way of N-Queen problem could be solved by using DFS-Backtracking Algorithm and of course recursively.

Author added mix of humor to the code e.g. firstLady until eigthBabyis a named variable for testing purposes that points to the first queen until the last queen to be added (since currently the N is 8 for my testing code).

Another example is Board struct has AbleToDate function like this:

func (b *Board) AbleToDate(homewrecker Queen) bool {
	for _, queen := range b.Queens {
		if homewrecker.MadnessPotential(queen) {
			return false
		}
	}
	return true
}

This function check whether the homeWrecker as a Queen could be able to fill up the list Queens that Board has or not.

I know right, you might found another one function that Queen has. MadnessPotential function contain all the constraints OR you could say the requirements that fulfill to date The King. And... Ba Dum Tss here are the requirements :

  • There should not be Queens on the same row.
  • And Queens are not allowed on the same column too.
  • Queens are also not allowed on the same diagonal.

Voila! Here is the function:

func (q1 *Queen) MadnessPotential(q2 Queen) bool {
	return q1.X == q2.X || q1.Y == q2.Y || math.Abs(float64(q1.X-q2.X)) == math.Abs(float64(q1.Y-q2.Y))
}

Usage

This repository doesn't have any dependency to any library. Create new directory:

cd /to/your/dev/dir
mkdir nameyouwanted
cd nameyouwanted

Using git clone to pull the repository:

git clone https://github.com/jojorancu/NQueen.git

There will be NQueen directory contains the code.

Test

Wanted to test ? Change the directory to the NQueen directory:

cd NQueen/

Use this syntax at the root directory:

go test -v ./...

Author

@jojorancu

nqueen's People

Contributors

jojorancu avatar jojorancuu avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.