Code Monkey home page Code Monkey logo

csp-solver's People

Contributors

igneus avatar komputerwiz avatar mooreniemi avatar tibbon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

csp-solver's Issues

release as a gem?

Would be nice if this lib followed standard Ruby convention and was installable as a gem. I'm happy to make a PR with that change if you're willing to release it on Rubygems.

I think a spec/ or test/ dir would be helpful too: one of my favorite ways to see how an API is used is to look at its tests. Likewise happy to provide one.

returns false on the zebra puzzle

Hi, nice library. I tried to solve the einstein zebra variant with this;

The Brit lives in a red house.
The Swede keeps dogs as pets.
The Dane drinks tea.
The green house is on the left of the white, next to it.
The green house owner drinks coffee.
The person who smokes Pall Mall rears birds.
The owner of the yellow house smokes Dunhill.
The man living in the house right in the center drinks milk.
The Norwegian lives in the first house.
The man who smokes blend lives next to the one who keeps cats.
The man who keeps horses lives next to the man who smokes Dunhill.
The owner who smokes Blue Master drinks beer.
The German smokes Prince.
The Norwegian lives next to the blue house.
The man who smokes blend has a neighour who drinks water.

With the following implementation:

require "csp"

problem = CSP::Solver::Problem.new

houses = %w(blue green red white yellow)
nation = %w(british danish german norwegian swedish)
drinks = %w(beer coffee milk tea water)
cigars = %w(master dunhill pall prince blend)
pet    = %w(cat bird dog fish horse)

entities = [houses, nation, drinks, cigars, pet]

entities.each do |e|
  problem.vars e, 1..5
  problem.all_different(e)
end

problem.constrain("british", "master"){ |b, m| b == m }
problem.constrain("swedish", "dog"){ |s, d| s == d }
problem.constrain("danish", "tea"){ |d, t| d == t }
problem.constrain("green", "white"){ |g, w| g == w - 1 }
problem.constrain("green", "coffee"){ |g, c| g == c }
problem.constrain("pall", "bird"){ |p, b| p == b }
problem.constrain("yellow", "dunhill"){ |y, d| y == d }
problem.assign "milk" => 3
problem.assign "norwegian" => 1
problem.constrain("blend", "cat"){ |b, c| (b - c).abs == 1 }
problem.constrain("master", "beer"){ |m, b| m == b }
problem.constrain("german", "prince"){ |g, p| g == p }
problem.constrain("norwegian", "blue"){ |n, b| (n - b).abs == 1 }
problem.constrain("blend", "water"){ |b, w| (b - w).abs == 1 }
p problem.solve

The result is: false

It was all fine until I got to the last constraint. Am I doing it wrong?

API/source-code discrepancy

Hi, thanks for writing this library!

In the API reference at http://komputerwiz.net/apps/csp-solver, it shows all_pairs, all_same, and all_different as having a splat operator in the argument, but the source code doesn't have it. I assume that instead of calling csp.all_different(:x, :y, :z) for example, it should be csp.all_different([:x, :y, :z]), correct?

Thanks again!

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.