Programming to Solve Einstein Riddle


Write a program to solve the classic “Einstein Riddle”. You can use Java, Python, R, C/C++.

Einstein’s Riddle

This classic riddle is claimed to have been written by Einstein but it is sometimes also attributed to Lewis Carrol, although there's no evidence that either of them actually wrote it. Regardless, it is an interesting problem that can be solved by logic but it also lends itself nicely as an AI programming exercise. There are many ways to code for this riddle – you are free to choose any approach you want. The riddle is:

There are five houses in five different colours in a row. In each house lives a person with a different nationality. The five owners drink a certain type of beverage, smoke a certain brand of cigar and keep a certain pet. No owners have the same pet, smoke the same brand of cigar, or drink the same beverage. Other facts:

The Brit lives in the red house.
The Swede keeps dogs as pets.
The Dane drinks tea.
The green house is on the immediate left of the white house.
The green house's owner drinks coffee.
The owner who smokes Pall Mall rears birds.
The owner of the yellow house smokes Dunhill.
The owner living in the centre house drinks milk.
The Norwegian lives in the first house.
The owner who smokes Blends lives next to the one who keeps cats.
The owner who keeps the horse lives next to the one who smokes Dunhill.
The owner who smokes Bluemasters drinks beer.
The German smokes Prince.
The Norwegian lives next to the blue house.
The owner who smokes Blends lives next to the one who drinks water.
The question is: who owns the fish?


This question belongs to programming and discusses about solving a classic Einstein’s riddle using programming.








Download Full Solution


  • HWA

    this is a very good website

  • HWA

    I have 50 questions for the same test your page is showing only 28

  • HWA

    hi can you please help or guide me to answer my assignments. thanks

  • HWA

    hi can anyone help or guide me to my assignments. thanks

  • HWA

  • HWA

    This solution is perfect ...thanks

  • HWA

    Hello Allison,I love the 2nd image that you did! I also, had never heard of SumoPaint, is something that I will have to exolpre a bit! I understand completely the 52 (or so) youtube videos that you probably watched. Sometimes they have what you want, sometimes they don't! However, it is always satisfying when you are able to produce something that you have taught yourself. Great job!Debra 0 likes

  • HWA

    Perfect bank of solution. 

  • HWA

    great !

  • HWA
    Paul Brandon-Fritzius

    thanks for the quick response. the solution looks good. :)

  • HWA
    tina Johnson

    thnx for the answer. it was perfect. just the way i wanted it. 

  • HWA

    works fine.