i need to find a k-length subset of list in prolog, i have this function:
subset([], []).
subset([E|Tail], [E|NTail]):-
subset(Tail, NTail).
subs
Using your initial solution to subset/2
, you might add another argument (Len) and:
That would look:
subset(0, [], []).
subset(Len, [E|Tail], [E|NTail]):-
succ(PLen, Len),
(PLen > 0 -> subset(PLen, Tail, NTail) ; NTail=[]).
subset(Len, [_|Tail], NTail):-
subset(Len, Tail, NTail).