Re: Need a Challenge?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Ok,  I'm guessing that one or more people have already solved this
programming puzzle problem by now, but I'm still trying, and I have (at
least?) one problem:

I don't know how to deal with "relative position" information in my
code/data structure ("The Norwegian lives NEXT DOOR to the blue house.", or
"The green house is on the RIGHT of the white house.
").   I CAN utilize some of that info, minimally (assert: Norwegian CAN'T
live in blue house), but I can't put "+or- 1" in my data structure (for
"next to"), which seems to be throwing away info, which seems bad.  And I
haven't figured out ANY way at all how to put "green position = white
position + 1" in my data structure.

What I have done is:
I have a reasonable algorithm for the puzzle, with a reasonable data
structure, I think;
I can choose and enter any info (except for relative position), including
"negative" info
(Norwegian house NOT blue) into the structure;
I can make info in one part of my structure be duplicated in parallel
"reverse" portions of it (eg, have things like "Nationality/Color" array,
AND "Color/Nationality" array, so I can enter all pairs of info; an entry in
one is auto duplicated properly in the "twin");
I can test all elements for "missing only one item", and fill in the missing
one
(ie, if something is: not this, not that, not this and that, etc, then MUST
be: the only remaining possibility); this is, I think, the main key to the
puzzle solution?
and I print out my data, and what is in the "Drink(water)/Nationality" and
"Pet(zebra)/Nationality" arrays.

I *may* have neglected to do that over & over again so newly filled in info
can be used to generate additional conclusions, and there *may* be other
logic tests I have also neglected to generate, and my code is LONG, and not
clear, too :(  , but I am trying.

Any suggestions for how to deal with "relative positions"?

Dan Moyer




----- Original Message -----
From: "Irv Mullins" <irvm at ellijay.com>
To: "EUforum" <EUforum at topica.com>
Sent: Wednesday, August 15, 2001 8:47 AM
Subject: Need a Challenge?


> >
> I found this puzzle in an example program for a language I downloaded.
> Can you write a program (100 lines or less, plz) to solve it?
>
> A small street has five differently colored houses on it. Five men
> of different nationalities live in these five houses. Each man has
> a different profession, each man likes a different drink, and each
> has a different pet animal. We have the following information:
>
> The Englishman lives in the red house.
> The Spaniard has a dog.
> The Japanese is a painter.
> The Italian drinks tea.
> The Norwegian lives in the first house on the left.
> The owner of the green house drinks coffee.
> The green house is on the right of the white house.
> The sculptor breeds snails.
> The diplomat lives in the yellow house.
> They drink milk in the middle house.
> The Norwegian lives next door to the blue house.
> The violinist drinks fruit juice.
> The fox is in the house next to the doctor's.
> The horse is in the house next to the diplomat's.
>
> The question is who has the zebra and who drinks water?
>
> Regards,
> Irv
>
> >
> >
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu