permuting lists
From: dirty_bit (dod_xenozhar_at_hotmail.com)
Date: 12/06/04
- Next message: el_bandido_at_nospam.com: "small puzzles"
- Previous message: Markus Triska: "Re: A simple problem, but a problem ..."
- Next in thread: Benjamin Johnston: "Re: permuting lists"
- Reply: Benjamin Johnston: "Re: permuting lists"
- Reply: student: "Re: permuting lists"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Dec 2004 17:37:13 -0800
I'm a prolog newbie and I'm trying to get some practice. What I would
like to do is create a rule that will permute a list. I'm trying to
get something to work sort of like this:
car_row(X) :- permute([red,blue,green,yellow],H),
permute([john,bill,mary,sue], P), join(H,P,X).
X would then be a list that might contain:
[car(yellow,bill), car(red,sue), car(blue,mary), car(green, john)]
I'm trying to use the select rule to make the first element of the
permuted list any element of the original list with the rest being a
permutation of the remaining elements of the original list, but so far
I'm having no luck. I would think that I could do this by defining
permute to recursively permute the remaining elements in the list sort
of like this:
permute([],[]).
permute(X,H) :- select(A,X,Rest), <Put A in H>, <select/permute from
Rest>.
I am confused as to how I get H to 'fill up' with all of the values
that were selected.
The join rule above will just be used to join the 2 lists together (I
can handle that ;) ).
Any help is appreciated!
- Next message: el_bandido_at_nospam.com: "small puzzles"
- Previous message: Markus Triska: "Re: A simple problem, but a problem ..."
- Next in thread: Benjamin Johnston: "Re: permuting lists"
- Reply: Benjamin Johnston: "Re: permuting lists"
- Reply: student: "Re: permuting lists"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]