File: zebra.pl

package info (click to toggle)
gprolog 1.3.0-6
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,708 kB
  • ctags: 8,388
  • sloc: ansic: 57,431; perl: 16,620; sh: 5,900; makefile: 1,284
file content (60 lines) | stat: -rw-r--r-- 1,572 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
% Where does the zebra live?
% Puzzle solution written by Claude Sammut.



zebra(ShowResult) :-
	houses(Houses),
	mymember(house(red, english, _, _, _), Houses),
	mymember(house(_, spanish, dog, _, _), Houses),
	mymember(house(green, _, _, coffee, _), Houses),
	mymember(house(_, ukrainian, _, tea, _), Houses),
	right_of(house(green,_,_,_,_), house(ivory,_,_,_,_), Houses),
	mymember(house(_, _, snails, _, winstons), Houses),
	mymember(house(yellow, _, _, _, kools), Houses),
	Houses = [_, _, house(_, _, _, milk, _), _,_],
	Houses = [house(_, norwegian, _, _, _)|_],
	next_to(house(_,_,_,_,chesterfields), house(_,_,fox,_,_), Houses),
	next_to(house(_,_,_,_,kools), house(_,_,horse,_,_), Houses),
	mymember(house(_, _, _, orange_juice, lucky_strikes), Houses),
	mymember(house(_, japanese, _, _, parliaments), Houses),
	next_to(house(_,norwegian,_,_,_), house(blue,_,_,_,_), Houses),
	mymember(house(_, _, zebra, _, _), Houses),
	mymember(house(_, _, _, water, _), Houses),
	(   ShowResult = true ->
	    print_houses(Houses)
	;   true).


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).

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

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



% benchmark interface

benchmark(ShowResult) :-
	zebra(ShowResult).

:- include(common).