forked from mmalita/PrologPuzzles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoccer.pl
54 lines (50 loc) · 2.02 KB
/
soccer.pl
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
/* File: soccer.pl
Title: 88. giant book of Mensa Mind challenges 2003 isbn 1-4027-1049-6
Five soccer teams United, County, Rovers, Albion, and Thistle took part in a league tournament.
Their colors were white, yellow, green, red, and blue. No teams were tied in the standings at the
end. From the following information determine for each team its captain, colors,
and position in which it finished in the league.
1. Rovers did not win the league, but finished higher than 4th
2. Neither Albion nor the team in green finished in the top three.
3. Evans captained the team in yellow.
4. Cooke's team finished a head of County which was captained by Dixon.
5. Allen's team finished second and Boyle's team finished last
6. The team in white finished lower than both United and the team in blue, but above Evans' team.
7. Albion was not the green team and United was not the blue team.
solution Team=[team,captain,color]
S=[[united,cooke,red],[rovers,allen,blue],[county,dixon,white],[albion,evans,yellow],[thistle,boyle,green]]
************************************************************************************/
:- encoding(utf8).
:- use_module(library(lists)).
start :-
S = [T1,T2,T3,T4,T5],
T1 = [H1,_N1,C1],
T2 = [H2,allen,C2],
T3 = [H3,_N3,C3],
T4 = [H4,_N4,C4],
T5 = [H5,boyle,C5],
Colors = [yellow,red,blue,white,green],
Teams = [united,albion,rovers,thistle,county],
permutation([C1,C2,C3,C4,C5],Colors),
permutation([H1,H2,H3,H4,H5],Teams),
H1 \== rovers, %1
before([rovers,_,_],T4,S),
member([_,evans,yellow],S), %2
([albion,_,_]=T4 ; [albion,_,_]=T5 ),
([_,_,green]=T4 ; [_,_,green]=T5 ), %2
member([albion,_,Ca],S),
Ca \== green,
member([united,_,Cu],S),
Cu \== blue, %7
before([_,cooke,_],[county,dixon,_],S),
before([united,_,_],[_,_,white],S), %6
before([_,_,blue],[_,_,white],S), %6
before([_,_,white],[_,evans,_],S), %6
write_list(S).
before(X,Y,L) :-
append(_,[X|T],L),
member(Y,T).
write_list(L) :-
forall(member(X,L),
(write(X), nl)
).