Giter Site home page Giter Site logo

generic-zebra-solver's Introduction

Generic Zebra Solver

A Prolog solver using CLPFD to any logic puzzle like the Zebra Puzzle

Build Status

Specification

Solver Predicate

The predicate solver(+Filename, -Solution) is satisfied when Solution is the solution of the logic puzzle specified by the file named Filename.

Puzzle definition

A puzzle is defined by a .prob file which consists in a list of domains and a list of constraints. There must be a blank line between the list of domains and the list of constraints.

List of Domains

The domain list consists of the domain name followed by a colon and the list of possible values separated by commas. Each domains must be in a single line. All domains must have the same nember of possible values.

The domain color with the colors blue, red, and black can be represented as follows:

color: blue, red, black

analogously nacionality can be defined as:

nacionality: german, spanish, italian

List of Constraints

A list of contraints consists of several constraints, one per line followed by an empty line.

Each constraint is represented by a logical expression which, by definition, is true. This expression is one of

  • LHS = RHS
  • LHS < RHS
  • LHS > RHS

where LHS and RHS are mathematical expressions.

A constraint can also be

  • LHS or RHS where LHS and RHS are one of the logical expressions defined above.

For simplicity sake let's define a value as either an integer or a variable. With that in mind a mathematical expression is one of

  • value
  • value + value
  • value - value
  • abs(mathematical_expression)

Some sample constraints are:

spanish = red + 1
german = blue
italian = 2
german = 3 or black - 2 = abs(red - blue)

Solution definition

Solution is a Prolog list of variable assignments. The first house is assumed to be number one.

Variable Assignment

A variable assignment consists of the functor c with arity 2 where the first argument is the variable name and the second is the its value, for example

[c(italian,2),c(spanish,3),c(german,1),c(black,3),c(red,2),c(blue,1)]

Contributing

Please fell free to fork, and create issues for any bugs/improvements/doubts.

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.