GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - justanothercell/logic_puzzle_solver: a solver for standard logic puzzles

BranchesTags
Open more actions menu

Latest commit

 

History

12 Commits
12 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
__pycache__
__pycache__
 
 
examples
examples
 
 
.gitgnore
.gitgnore
 
 
__init__.py
__init__.py
 
 
lps.py
lps.py
 
 
sets.py
sets.py
 
 
solver.py
solver.py
 
 

Repository files navigation

Logic Puzzle Solver

This engine can solve logic puzzles with 1:1 correspondances between discrete sets of equal size and unique elements.

Example

examples

Task

[taken from Question 1 of the KIT University Computer Science Self Assessment Test, translated from german]

The three friends Anne, Anja and Anke visit the courses software technic, algorythms and programming paradigms with varying degrees of success (1.7/2.6/3.8). (note: in Germany the grading system is from 1 (best) to 6 (worst)) They search for their results in a list under the names Becker, Kramer and Wolff.

  1. Anne passed with a grade of 2.6.
  2. Anja took the course algorythms. She has a better grade than student Wolff.
  3. Anke did not take programming paradigms.

Step 0: Imports

from solver import Model
from sets import Set, OrderedSet

Step 1: Create the datasets

names = Set('names', ['anne', 'anja', 'anke'])
last_names = Set('last_names', ['becker', 'kramer', 'wolff'])
subjects = Set('subjects', ['software', 'algorythms', 'paradigms'])
grades = OrderedSet('grades', [1.7, 2.6, 3.8])

Step 2: Create the model

model = Model(names, last_names, subjects, grades)

Step 3: Create the relations

# == 1 ==
# read: `the grade of anne is 2.6` / `the grade related to the name anne is 2.6`
model.relate(names['anne'](grades) == 2.6)
# which is the same as:
# model.relate(names['anne'] == grades[2.6])
# == 2 ==
model.relate(names['anja'] == subjects['algorythms'])
model.relate(names['anja'](grades) < last_names['wolff'](grades))
# == 3 ==
model.relate(names['anke'] != subjects['paradigms'])
model.relate((names['anke'] & last_names['kramer']) > grades[1.7])
# the `&` above is a short form for the 2 following relations:
# model.relate(names['anke'] > grades[1.7])
# model.relate(last_names['kramer'] > grades[1.7])
# We can deduce that anke is not named kramer, but the machine cannot since it does not know how names work.
# This is why we must specify this additional constraint.
model.relate(names['anke'] != last_names['kramer'])

Step 4: Evaluate the relations

solver = model.solver()

# a `ValueError` is thrown if there are not enough constraints to solve the model fully
# or the model ran for too few iterations (unlikey for small models).
# Check whether oyur input text allows you to deduce another formal statement whcih you didnt notice before.
# If there is a sttement error, aka no element from a set satisfies the conditions,
# a `ArithemeticError` is thrown. This should be due to an input error by the user.
try:
    solution = solver.solve()
    print(solution)
except ValueError:
    print(solver)

Result

names last_names subjects grades
anne kramer paradigms 2.6
anja becker algorythms 1.7
anke wolff software 3.8

About

a solver for standard logic puzzles

Topics

logiclogic-solver

Resources

Readme
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.