Re: Sorting a list of lists in the order of ascending length
Markus Triska <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hi Norbert, "Norbert E. Fuchs" <[email protected]> writes: > I need all subsets of a list in the order of ascending length What about: set_ascending_length_subset(Set, Sub) :- length(Set, N), between(0, N, L), length(Sub, L), phrase(subset(Set), Sub). subset([]) --> []. subset([L|Ls]) --> ( [L] ; []), subset(Ls). Example: ?- findall(Sub, set_ascending_length_subset([a,b,c], Sub), Subs). %@ Subs = [[], [a], [b], [c], [a, b], [a, c], [b, c], [a|...]]. All the best, Markus