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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prolog lists question

Status
Not open for further replies.

zoharetzioni

Programmer
Joined
Mar 17, 2004
Messages
1
Location
IL
I have a solution for an instance of langford's numbers problem, and I want to generalize it, but I'm lacking some prolog tools.

For n=3 and k=2
I would write a predicate as following:
sequence([_,_,_,_,_,_]).
solve(L):-
sequence(L),
sublist([3,_,_,_,3],L),
sublist([2,_,_,2],L),
sublist([1,_,1],L).

The logics for generalizing is trivial but how you do it in prolog?

The algorithms is:
for all i:1..n
do
generate list containing k instances of i in i distance /* (i,_,_,...i,...) */
sublist(L1,L)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top