Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Einstein Problem-Lite by LMAO
from itertools import product
NUMBERS = ['1', '2', '3', '4', '5']
COLORS = ['blue', 'green', 'red', 'white', 'yellow']
NATIONALITY = ['Brit', 'Dane', 'German', 'Norwegian', 'Swede']
BEVERAGES = ['beer', 'coffee', 'milk', 'tea', 'water']
CIGARETTES = ['Rothmans', 'Dunhill', 'Pall Mall', 'Winfield', 'Marlboro']
PETS = ['cat', 'bird', 'dog', 'fish', 'horse']
ATTRS = [NUMBERS, COLORS, NATIONALITY, BEVERAGES, CIGARETTES, PETS]
QUESTIONS = ["number", "color", "nationality", "beverage", "cigarettes", "pet"]
def answer(relations, question):
relations = [set(r.split('-')) for r in relations]
all_patterns = product(*ATTRS)
houses = (house for house in all_patterns if all(len(set(house) & r) != 1 for r in relations))
val, name = question.split('-')
for house in houses:
if val in house:
return house[QUESTIONS.index(name)]
Feb. 24, 2015
Comments: