Skip to content

dmackinnon1/portia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

portia

In Shakespeare's The Merchant of Venice, Portia tested her suitors by asking them to discover which of three caskets concealed her portrait. Inscriptions on the caskets presented riddles that would challenge the virtue of her potential mates. In his classic What is the Name of this Book? logician Raymond Smullyan, imagined several generations of clever Portias, who presented potential suitors with caskets inscribed with logic puzzles that provided the key to finding her hidden portrait.

On this page you can play with sets of puzzles that correspond (roughly) to Smullyan’s first three generations of Portias. This repo contains to code for this page, as well as a work-in-progress LaTeX book version of some of the puzzles.

In these puzzles there are three caskets with statements on them.In "Portia I" each casket has one statement about the location of the portrait. A clue is provided that indicates how many of the statements are true. Solving the puzzle involves determining the placement of the portrait that makes the correct number of statements on the casket true.

Generating puzzle data

Ensuring that the directory /portia/data is created and writable, the puzzle data is generated by running the Python script portia.py in the build directory.

> python portia.py

Expected output is:

Generating Portia I data.
 --- creating file ../data/portia1.json
generated 348 puzzles
 --- completed writing out Portia I data.
-------------------------------------------
Generating Portia II data.
 --- creating file ../data/portia2.json
generated 30480 puzzles
 --- completed writing out Portia II data.
-------------------------------------------
Generating Portia III data.
 --- creating file ../data/portia3.json
generated 3600 puzzles
 --- completed writing out Portia III data.
-------------------------------------------

Each puzzle type has its own format:

Portia 1

{
  "caskets": [1,2,2],
  "truths": 0,
  "solution": 3,
  "position": "min",
  "id": "portia1-20"
}

Portia 2

{
  "caskets": [[1,1,3],[-1,-3,-3]],
  "truths": [1,0,1],
  "solution": 3,
  "id": "portia2-358"
}

Portia 3

{
  "caskets": [[1,1,2],[3,1,-2]],
  "truths": [0. 0, 0],
  "solution": 3,
  "id": "portia3-24"
}

Solving and generating the puzzles

One way to solve problems like this is to work backwards. For each casket, imagine that the portrait is concealed within that casket, then count how many statements would be true. When you find the portrait placement that matches the requirement in the clue (for example, that "at most one is true") you have your solution.

Working backwards also gives us a way to generate puzzles like the "portial 1" puzzles, where each casket has one statement on it and To generate these puzzles, consider all possible statements on the caskets. Each set of statements gives you three possible puzzles: a puzzle where the portrait is in the gold casket, a puzzle where the portrait is in the silver casket, and a puzzle where it is in the lead casket. To find out if any (or all) of these are valid solvable puzzles, check to see if the portrait placement gives you a 'truth count' that unique within that group of potential puzzles.

About

A generator for 'Portia's Caskets'

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors