MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Logic Programming

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29670] Re: Logic Programming
  • From: "Herwig Habenbacher" <habenb at hilti.com>
  • Date: Tue, 3 Jul 2001 04:40:24 -0400 (EDT)
  • References: <9hp4r6$2er$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Looks like the "classic" "Zebra" puzzle...

It was used in the Prolog community to test your own programming skills and
the speed of the Prolog implementation too...

Here a solution found in some Prolog packages.

Regards,

   Herwig

---------------------------------------------------------
Herwig Habenbacher             Scientific Computing (FII)
Hilti AG - Technical Centre       eMail: habenb at hilti.com
FL - 9494 Schaan                    voice: ++423 234 2169
Principality of Liechtenstein         fax: ++423 234 2379



% Where does the zebra live?
% Puzzle solution written by Claude Sammut.
go :-
 houses(Houses),
 a_member(house(red, english, _, _, _), Houses),
 a_member(house(_, spanish, dog, _, _), Houses),
 a_member(house(green, _, _, coffee, _), Houses),
 a_member(house(_, ukrainian, _, tea, _), Houses),
 right_of(house(green,_,_,_,_), house(ivory,_,_,_,_), Houses),
 a_member(house(_, _, snails, _, winstons), Houses),
 a_member(house(yellow, _, _, _, kools), Houses),
 Houses = [_, _, house(_, _, _, milk, _), _,_],
 Houses = [house(_, norwegian, _, _, _)|_],
 next_to(house(_,_,_,_,chesterfields), house(_,_,fox,_,_), Houses),
 next_to(house(_,_,_,_,kools), house(_,_,horse,_,_), Houses),
 a_member(house(_, _, _, orange_juice, lucky_strikes), Houses),
 a_member(house(_, japanese, _, _, parliaments), Houses),
 next_to(house(_,norwegian,_,_,_), house(blue,_,_,_,_), Houses),
 a_member(house(_, _, zebra, _, _), Houses),
 a_member(house(_, _, _, water, _), Houses),
 print_houses(Houses).

houses([
 house(_, _, _, _, _),
 house(_, _, _, _, _),
 house(_, _, _, _, _),
 house(_, _, _, _, _),
 house(_, _, _, _, _)
]).

right_of(A, B, [B, A | _]).
right_of(A, B, [_ | Y]) :- right_of(A, B, Y).

next_to(A, B, [A, B | _]).
next_to(A, B, [B, A | _]).
next_to(A, B, [_ | Y]) :- next_to(A, B, Y).

a_member(X, [X|_]).
a_member(X, [_|Y]) :- a_member(X, Y).

print_houses([A|B]) :- !,
 write(A), nl,
 print_houses(B).
print_houses([]).




  • Prev by Date: AW: Making a LIst Reconsidered
  • Next by Date: Re: Transforming matrices
  • Previous by thread: Logic Programming
  • Next by thread: Re: Question: How to display matrixes with a tube-defined figure