![]() Using the skills so far learned I managed to implement a Python code for solving the so-called Einstein's Riddle. I solved the problem in two ways, first the straightforward way by using lists and list comprehensions, etc. Then I refactored to code using the Python object model, by deriving new datatypes from the Python list object. This object-oriented version (updated the link on May 29, 2007) is about 50% slower, but easier to understand. Here follows a short extract from the object-oriented version: def alltrue(l, op=operator.and_): return reduce(op, l)My input data was in Finnish, so I'm afraid the following result may be difficult to read: 1 2 3 4 5 kelt sini pun vihr valk norja tanska suomi saksa ruotsi vesi tee maito kahvi olut blues ooppera rock iskelma hevi kissa hevonen lintu kalat koira(Also, I don't like smoking, so I changed that part of the data to different types of music.) But what is the final solution? Well, the German ('saksa') owns the fish ('kalat') in house 4. Here is a follow-up question. What if we interpret the rule 4. The Green house is on the left of the White house.so that there may be houses between the Green and White house. How many different solutions do you get?
|
![]() Camilo commented The Mathematics of Marriage: "I read James Murray's Mathematical Biology, and it is awesome; he is one of the authors of the book, and a superb researcher and expert in NLD. I do intend to get my hands on this book!"
|