Dear fellow monks,
being a novice I try to improve my skills by solving the following problem with perl. It is said to be invented by Albert Einstein who believed only 2 percent of the world population could solve it. He had no idea of perl or the monastery, of course ;^)
So here's the task:
1. There are five houses with different colours.
2. In each of the houses there lives a member of a different nation.
3. Each one of these people likes a special drink and a special cigarrette best and has a special pet.
4. None of the 5 persons likes the same drink or cigarrete best or has the same pet as one of his neighbours.
To whom belongs the fish?
The British lives in the red house.
The Swedish has a dog.
The Danish likes tea.
The green house is standing left of the white house.
The owner of the green house drinks coffee.
The person smoking Pall Mall, has a bird.
The man living in the middle house, drinks milk.
The owner of the yellow house smokes Dunhill.
The Norwegian lives in the first house.
The Marlboro-smoker's neighbour has a cat.
The man with the horse lives next to the Dunhill-smoker.
The Winfiels-smoker drinks beer.
The Norwegian lives beneath the blue house.
The German smokes Rothmanns.
The Marlboro-smoker has a neighbour who drinks water.
I think of creating an array of five hashes (with the six keys: house_number, colour, drink, cigarette, pet, and nation). One could then fill out the known attributes and try to move the hashes around the array until each but one field is filled.
So far the thoughts of a poor brain ... Can anyone please tell me if this might be the right start and how to get on?
Having solved the problem by hand, there is another question: How comes, that the German doesn't drink beer? ;^)
Thanks for your help!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||