Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question regarding lists

Status
Not open for further replies.

freakman305

Programmer
Feb 12, 2011
1
0
0
GB
Hi everyone, im new to prolog and have just started learning it and i've just struck a problem which i just cant get my head around. heres the code and underneath is what i cant seem to figure out.

leader('adam smith').
leader('harry tills').
leader('robert johnson').
leader('niam popper').
leader('tom crow').
leader('tim burton').
leader('arnold ghets').

ingroup('adam smith',star).
ingroup('harry tills',star).
ingroup('robert johnson',elephant).
ingroup('niam popper',giraffe).
ingroup('tom popper',giraffe).
ingroup('tim burton',dog).
ingroup('arnold ghets',cat).

start('adam smith',1721).
start('harry tills',1743).
start('robert johnson',1812).
start('niam popper',1846).
start('tom crow',1916).
start('tim burton',1922).
start('arnold ghets',1945).

end('adam smith',1742).
end('harry tills',1754).
end('robert johnson',1827).
end('niam popper',1851).
end('tom crow',1922).
end('tim burton',1923).
end('arnold ghets',1951).

leaderduring(X,Y):-
start(Y,Z),
end(Y,W),
X >= Z,
X =< W.

leadersucceeded(X,Y):-
end(X,Z),
began(Y,W),
Z =< W.

listofleaders([]).
listofleaders([X | Rest]):-
leaderduring(X,Y),
print(Y),nl,
listofleaders(Rest).

groups([], In, In).
groups([Year | Years], In, Out):-
leaderduring(Year,Z),
ingroup(Z,X),
groups(Years,[Year | In],Out).
groups([ _Year | Years],In, Out):-
groups(Years, In, Out).

I need to make a rule called groups with three arguments, the first a list (of years), the second a group name. The rule should be queried with the first argument a list of years and the second a group name, and will result in the third argument instantiated to a list consisting of occurrences of ‘in’ or ‘out’ indicating whether or not the leader at the start of the corresponding year was of the given group. For example, query group([1947, 1870], cat, X). would result in X = [yes,
no]

Please help, i just cant seem to get it to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top