zoharetzioni
Programmer
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)
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)