Question: This code is for solving the Einstein Who Owns the Fish puzzle. Right now all I get is No solution found. I can't post the
This code is for solving the Einstein Who Owns the Fish puzzle. Right now all I get is No solution found. I can't post the whole code but here is snippets of the logic:
import java.util.Arrays;
public class WhoOwnsTheFish
Constants for each possible value
private final int NONE ;
private final int NATIONALITY ;
private final int COLOR ;
private final int DRINKS ;
private final int SMOKES ;
private final int PET ;
private final int NORWEGIAN ;
private final int DANE ;
private final int BRIT ;
private final int GERMAN ;
private final int SWEDE ;
private final int WATER ;
private final int TEA ;
private final int COFFEE ;
private final int BEER ;
private final int MILK ;
private final int DUNHILLS ;
private final int BLENDS ;
private final int PALLMALLS ;
private final int PRINCES ;
private final int BLUEMASTERS ;
private final int CAT ;
private final int HORSE ;
private final int BIRD ;
private final int FISH ;
private final int DOG ;
private final int BLUE ;
private final int GREEN ;
private final int RED ;
private final int YELLOW ;
private final int WHITE ;
public boolean valid int houses, int h int a int value
is the value assigned to another house
forint i ; i houses.length; i
ifi h && housesia value
return false;
switch case to check the attribute and the value
switcha
START HERE
the brit lives
case NATIONALITY:
if value BRIT && houseshCOLOR NONE && houseshCOLOR RED
return false;
the Swede keeps dogs as pets
if value SWEDE && houseshPET NONE && houseshPET DOG
return false;
the Dane drinks tea
ifvalue DANE && houseshDRINKS NONE && houseshDRINKS TEA
return false;
the Norwegian lives in the first house
ifvalue NORWEGIAN && h
return false;
the German smokes Princes
ifvalue GERMAN && houseshSMOKES NONE && houseshSMOKES PRINCES
return false;
break;
case COLOR:
the Brit lives in the red house
ifvalue RED && houseshNATIONALITY NONE && houseshNATIONALITY BRIT
return false;
the green house is on the left of and next to the
white house
ifvalue GREEN && h housesh COLOR NONE && housesh COLOR WHITE
return false;
if value WHITE && h housesh COLOR NONE && housesh COLOR GREEN
return false;
the owner of the yellow house smokes dunhills, which means that the owner of the yellow house is the Norwegian
ifvalue YELLOW && houseshSMOKES NONE && houseshSMOKES DUNHILLS
return false;
the Norwegian lives next to the blue house
if value BLUE && h && h housesh NATIONALITY NONE && housesh NATIONALITY NORWEGIAN
return false;
break;
case DRINKS:
the green houses owner drinks coffe, which is the German
ifvalue COFFEE && houseshNATIONALITY NONE && houseshCOLOR GREEN
return false;
if value TEA && houseshNATIONALITY NONE && houseshNATIONALITY DANE
return false;
the man living in the center house drinks milk
ifvalue MILK && h
return false;
The owner who smokes Bluemasters drinks beer
if value BEER && houseshSMOKES NONE && houseshSMOKES BLUEMASTERS
return false;
The man who smokes Blends has a neighbor who drinks water
if value WATER && h h housesh SMOKES NONE && housesh SMOKES BLENDS && h h housesh SMOKES NONE && housesh SMOKES BLENDS
return false;
break;
case SMOKES:
The person who smokes Pall Mall rears birds
if value PALLMALLS && houseshPET NONE && houseshPET BIRD
return false;
The owner of the yellow house smokes Dunhills
if value DUNHILLS && houseshCOLOR NONE && houseshCOLOR YELLOW
return false;
The man who smokes Blends li
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
