Maslor / knight-or-knave

Knowledge-representation focused implementation of the "Knights and Knaves" puzzle.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

knight-or-knave

Knowledge-representation focused implementation of the "Knights and Knaves" puzzle.

background

In 1978, logician Raymond Smullyan published “What is the name of this book?”, a book of logical puzzles. Among the puzzles in the book were a class of puzzles that Smullyan called “Knights and Knaves” puzzles.

In a Knights and Knaves puzzle, the following information is given: Each character is either a knight or a knave. A knight will always tell the truth: if knight states a sentence, then that sentence is true. Conversely, a knave will always lie: if a knave states a sentence, then that sentence is false.

The objective of the puzzle is, given a set of sentences spoken by each of the characters, determine, for each character, whether that character is a knight or a knave.

For example, consider a simple puzzle with just a single character named A. A says “I am both a knight and a knave.”

Logically, we might reason that if A were a knight, then that sentence would have to be true. But we know that the sentence cannot possibly be true, because A cannot be both a knight and a knave – we know that each character is either a knight or a knave, but not both. So, we could conclude, A must be a knave.

That puzzle was on the simpler side. With more characters and more sentences, the puzzles can get trickier! Your task in this problem is to determine how to represent these puzzles using propositional logic, such that an AI running a model-checking algorithm could solve these puzzles for us.

Source

The logic.py library was forked from Harvard's CS50 Introduction to Artificial Intelligence course.

About

Knowledge-representation focused implementation of the "Knights and Knaves" puzzle.


Languages

Language:Python 100.0%