Using Alloy to Solve the Einstein Puzzle

Slides:



Advertisements
Similar presentations
Solving the Einstein puzzle Carol Mullen MST Summer Program 2006 Daemen College.
Advertisements

Colors and Numbers.
Basic Basic colorscolors الوان رئيسية What color is it ? It is red. Red This is a red fish. The fish is red. This is a red apple. The apple is red.
This is a self running presentation that lasts about 4 minutes, and loops continuously until escape is pressed. The text appears one word at a time to.
Lab 1 Chapter 1, Sections 1.1, 1.2, 1.3, and 1.4 Book: Discrete Mathematics and Its Applications By Kenneth H. Rosen.
Logic Puzzle Smith. The Setup There are five houses Each of a different color Inhabited by men of different nationalities Each has a different pet Each.
Bill Martin Jr. and Eric Carle
4/18/2005EE5621 EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS Lecture 6, 4/20/2005 University of Washington, Department of Electrical Engineering Spring.
BROWN BEAR, BROWN BEAR, WHAT DO YOU SEE?
DCP 1172, Homework 2 1 Homework 2 for DCP-1172 ( ) This time, we have 3 different homework assignments.  Homework assignment 2-1 (50%, Ch3 &
Brown bear, brown bear, What can you see? I can see a red bird Looking at me.
Opening Questions What do you think is an appropriate measure of intelligence? How important do you think it is to know how intelligent you are?
6 < > 99 8 = 8 Click mouse for next screen. Lesson 2.
MEMORY: - LEVELS AND TYPES OF MEMORY, CASE STUDIES Memory is the capacity to acquire, retain and recall knowledge and skills.
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
Logic Puzzles Break out Session and Resources. Ph.D. Training – Published Piled Higher and Deeper by Jorge Chamwww.phdcomics.comwww.phdcomics.com.
Bet You Can’t The –et word family G E T You get a lot of different candy for Halloween!
Kindergarten Sight Words Level A I I like books.
Puzzle A Puzzle B. When asked about his birthday, a man said: "The day before yesterday I was only 25 and next year I will turn 28." This is true only.
Fractions, Decimals, and Percents
#tbt #4 Who Owns The Zebra?
My Favorite Things Book My name is: ________________________________ Level 3 C. Galijasevic/IPSD204/2014.
11-5 Square Challenge
Who owns the zebra?. Here’s a small logical puzzle for you. Copy down the information you see. Through elimination, can you discover who owns the zebra.
Let’s do phonetic exercises. Let’s go to the shop!
Grade 5 Module 3 Lesson 1: Problem Set.
4/18/2005EE5621 EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS Lecture 5, 4/18/2005 University of Washington, Department of Electrical Engineering Spring.
Constraint Satisfaction Problems
Section 0.3.  How many seconds are in a calendar year?  How can we convert 1 year to seconds?  What other time measurements do you know? ◦ 1 year =
Dolphins “R” Us It’s Who We Are!! BrittanyLindsayNicholeChristina.
I see a red bird Brown Bear, Brown Bear, looking at me. What do you see?
Algebra 1 Two-Way Frequency Tables. Use the table below to answer the following questions. 1.How many people chose cats as their preferred pet? 2.How.
The small boy. Has run away The yellow cat He is.
Brown Bear, Brown Bear, What Do You See?
Colors brown red yellow blue green purple white gold.
Brown Bear, Brown Bear, What Do You See?
Brown Bear, Brown Bear, What Do You See. Written by Bill Martin, Jr
Silly starter Clicker question
ASL Club October 7th, 2015.
Logic Puzzle.
Using Alloy to Design a Safe Traffic Light System
Constraint Satisfaction Problems
Sorting and Grouping.
This is a self running presentation that lasts about 4 minutes, and loops continuously until escape is pressed. The text appears one word at a time to.
What do cats eat ? They eat … 2A : Unit 8.
Silly starter Clicker question
Phrases with First 100 Popper Words
Clues 1 The Brit lives in the red house 2 The Swede keeps dogs as pets 3 The Dane drinks tea 4 As you look at the houses from across the street, the.
Solving the ‘Einstein” puzzle
the people Write it down. by the water.
Colour Farm Dr. Jean.
Brown Bear, Brown Bear, What Do You See?
Building your Dream Team
KINDERGARTEN HIGH FREQUENCY WORD LIST
THE DOG The dog is our good friend. It is very clever. The dog knows and loves its master and the friends of his family. It likes to eat meat and drink.
Each hotel guest has a set of keys and no two guests have the same key
The Color Farm Tune: “Bingo”
A good idea Unit11 苏州市金阊外国语实验学校 杨家洁.
Use Alloy to model and find a solution to the Farmer, Goat, Cabbage, and Wolf problem Roger L. Costello July 14, 2018.
When will we go 1.
Cat school dog bird panda desk classroom chair.
START.
Encapsulation in Alloy
Desktop model Roger L. Costello March 24, 2018 Desktop0 Desktop1
What Color is it?.
Colour Farm Dr. Jean.
Einstein’s Riddle.
Read the phrases before the slide changes for fluency practice.
☺.
Fluency Phrases Set 2.
Presentation transcript:

Using Alloy to Solve the Einstein Puzzle Roger L. Costello May 7, 2018

Einstein Puzzle The legend says that this problem was created by Albert Einstein in the last century and Einstein said that only 2% of the world could solve it.

Description of the problem There are five houses of different colors next to each other on the same road. In each house lives a man of a different nationality. Every man has his favorite drink, his favorite brand of cigarettes, and keeps pets of a particular kind.

Constraints The Englishman lives in the red house. The Swede keeps dogs. The Dane drinks tea. The green house is just to the left of the white one. The owner of the green house drinks coffee. The Pall Mall smoker keeps birds. The owner of the yellow house smokes Dunhills. The man in the center house drinks milk. The Norwegian lives in the first house. The Blend smoker has a neighbor who keeps cats. The man who smokes Blue Masters drinks beer. The man who keeps horses lives next to the Dunhill smoker. The German smokes Prince. The Norwegian lives next to the blue house. The Blend smoker has a neighbor who drinks water.

Question Who has fish?

Solution I expressed the constraints in the Alloy language and then ran the Alloy Analyzer to find instances (solutions). One instance was found: color: yellow nationality: Noregian drink: water cigarette: Dunhills pet: cat House1 color: blue nationality: Dane drink: tea cigarette: Blend pet: horse House2 color: red nationality: Englishman drink: milk cigarette: Pall_Mal pet: bird House3 color: green nationality: German drink: coffee cigarette: Prince pet: fish House4 color: white nationality: Swede drink: beer cigarette: Blue_Masters pet: dog House5 You can see that it satisfies all the constraints. The answer to the question is: The German has fish (house #4).

Let’s model this system First, there are a set of houses. Each house has a color. The resident has a nationality, a favorite drink, a favorite cigarette, and a pet. Here’s how to express the set of houses: sig House { color: Color, nationality: Nationality, drink: Drink, cigarette: Cigarette, pet: Pet }

House are ordered The houses are ordered – there is a first house, a second house, a last house. Use the ordering module to order the set of houses: open util/ordering[House]

Each house has a different color Create the set of colors that houses may have: enum Color { red, green, yellow, blue, white }

Each resident has a different nationality Create the set of nationalities: enum Nationality { Englishman, Swede, Dane, German, Norwegian }

Each resident has a different favorite drink Create the set of drinks: enum Drink { tea, coffee, milk, beer, water }

Each resident has a different brand of cigarettes Create the set of cigarette brands: enum Cigarette { Pall_Mall, Dunhills, Blend, Blue_Masters, Prince }

Each resident has a different pet Create the set of pets: enum Pet { dog, bird, horse, cat, fish }

There are five houses, each of a different color some disj h1, h2, h3, h4, h5: House | h1.color = red and h2.color = green and h3.color = yellow and h4.color = blue and h5.color = white The keyword disj (disjoint) means that h1, h2, …, h5 denote different houses. One house has the color red, another has the color green, etc. Note: this does not say that the first house has color red, the second house has color green, etc. It just says that some house has color red, some house has color green, etc.

The resident in each house is of a different nationality There is no occurrence of two different houses h and h’, where the nationality of the resident in h is the same as the nationality of the resident in h’: no disj h,h': House | h.nationality = h'.nationality

1. The Englishman lives in the red house 1. The Englishman lives in the red house. That is, there is some house h such that the nationality of h’s resident is Englishman and the color of h is red. some h: House | (h.nationality = Englishman) and (h.color = red) 2. The Swede keeps dogs. some h: House | (h.nationality = Swede) and (h.pet = dog) 3. The Dane drinks tea. some h: House | (h.nationality = Dane) and (h.drink = tea) 4. The green house is just to the left of the white one. That is, there are two houses h and h’ such that h is green, h’ is white, and h occurs before h’ (recall the houses are ordered). some disj h, h': House | (h.color = green) and (h'.color = white) and (h'.prev = h) 5. The owner of the green house drinks coffee. some h: House | (h.color = green) and (h.drink = coffee)

6. The Pall Mall smoker keeps birds. some h: House | (h.cigarette = Pall_Mall) and (h.pet = bird) 7. The owner of the yellow house smokes Dunhills. some h: House | (h.color = yellow) and (h.cigarette = Dunhills) 8. The man in the center house drinks milk. For a house to be in the “center” there must be some house two houses to the left and two houses to the right, i.e., prev.prev and next.next some h: House | (some h.prev.prev) and (some h.next.next) and (h.drink = milk) 9. The Norwegian lives in the first house. some h: House | (h = first) and (h.nationality = Norwegian) 10. The Blend smoker has a neighbor who keeps cats. There are two houses h and h’ such that the brand of cigarette preferred by the resident in h is Blend, and the resident in h’ has a cat and h’ is either one house to the left or one house to the right. some disj h, h': House | (h.cigarette = Blend) and (h'.pet = cat) and ((h.prev = h') or (h.next = h'))

11. The man who smokes Blue Masters drinks beer. some h: House | (h.cigarette = Blue_Masters) and (h.drink = beer) 12. The man who keeps horses lives next to the Dunhill smoker. some disj h, h': House | (h.pet = horse) and (h'.cigarette = Dunhills) and ((h.next = h') or (h.prev = h')) 13. The German smokes Prince. some h: House | (h.nationality = German) and (h.cigarette = Prince) 14. The Norwegian lives next to the blue house. From constraint #9 we know that the Norwegian lives in the first house. So, the blue house must be to the right of the Norwegian house. some disj h, h': House | (h.nationality = Norwegian) and (h'.color= blue) and (h.next = h') 15. The Blend smoker has a neighbor who drinks water. some disj h, h': House | (h.cigarette = Blend) and (h'.drink = water) and ((h.next = h') or (h.prev = h'))

Do Lab2 open util/ordering[House] sig House { color: Color, nationality: Nationality, drink: Drink, cigarette: Cigarette, pet: Pet } enum Color { red, green, yellow, blue, white } enum Nationality { Englishman, Swede, Dane, German, Norwegian } enum Drink { tea, coffee, milk, beer, water } enum Cigarette { Pall_Mall, Dunhills, Blend, Blue_Masters, Prince } enum Pet { dog, bird, horse, cat, fish } fact constraints { // There are five houses, each of a different color. some disj h1, h2, h3, h4, h5: House | h1.color = red and h2.color = green and h3.color = yellow and h4.color = blue and h5.color = white // In each house lives a man of a different nationality. no disj h,h': House | h.nationality = h'.nationality // 1. The Englishman lives in the red house. some h: House | (h.nationality = Englishman) and (h.color = red) // 2. The Swede keeps dogs. some h: House | (h.nationality = Swede) and (h.pet = dog) // 3. The Dane drinks tea. some h: House | (h.nationality = Dane) and (h.drink = tea) // 4. The green house is just to the left of the white one. some disj h, h': House | (h.color = green) and (h'.color = white) and (h'.prev = h) // 5. The owner of the green house drinks coffee. some h: House | (h.color = green) and (h.drink = coffee) // 6. The Pall Mall smoker keeps birds. some h: House | (h.cigarette = Pall_Mall) and (h.pet = bird) // 7. The owner of the yellow house smokes Dunhills. some h: House | (h.color = yellow) and (h.cigarette = Dunhills) // 8. The man in the center house drinks milk. some h: House | (some h.prev.prev) and (some h.next.next) and (h.drink = milk) // 9. The Norwegian lives in the first house. some h: House | (h = first) and (h.nationality = Norwegian) // 10. The Blend smoker has a neighbor who keeps cats. some disj h,h': House | (h.cigarette = Blend) and (h'.pet = cat) and ((h.prev = h') or (h.next = h')) // 11. The man who smokes Blue Masters drinks beer. some h: House | (h.cigarette = Blue_Masters) and (h.drink = beer) // 12. The man who keeps horses lives next to the Dunhill smoker. some disj h,h': House | (h.pet = horse) and (h'.cigarette = Dunhills) and ((h.next = h') or (h.prev = h')) // 13. The German smokes Prince. some h: House | (h.nationality = German) and (h.cigarette = Prince) // 14. The Norwegian lives next to the blue house. some disj h,h': House | (h.nationality = Norwegian) and (h'.color= blue) and (h.next = h') // 15. The Blend smoker has a neighbor who drinks water. some disj h,h': House | (h.cigarette = Blend) and (h'.drink = water) and ((h.next = h') or (h.prev = h')) run {} for 5 Do Lab2