Home > Archive > Prolog > June 2005 > List
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| martin 2005-06-09, 8:57 pm |
| Hello,
I want to generate all lists that consit four pairs of numbers (1..9). So
the list should 36 elements. I wanted to find all permutations of a set
[1,1,1,1,2,2,2,2,......,8,8,8,8,9,9,9,9] but it's not a good solutions
becuase then I get lists that look the same but are different permutations
of the set. Because of that fact I get much more solutions than I want and
testing generated lists takes too much time. Thanks for help
regard,
martin
| |
| tmp123 2005-06-10, 3:59 pm |
| A simple method, I hope it useful:
| p([[A|B]|Q],A,QR) :-
| B=[] -> QR=Q; QR=[B|Q].
| p([H|Q],A,[H|QR]) :- p(Q,A,QR).
|
| r([],[]).
| r(I,[H|Q]) :-
| p(I,H,T),
| r(T,Q).
Filter of students looking for skip homework: how to use it.
Kind regards.
|
|
|
|
|