Acorn Arcade forums: Programming: PROLOG Lists pleas help
|
PROLOG Lists pleas help |
|
gilly_uk (20:31 30/11/2002)
|
|
andrew |
Message #25727, posted by gilly_uk at 20:31, 30/11/2002 |
Member
Posts: 1
|
Im revising for an exam next week and i cant get my head round this exercise in the notes i have. Its asks to use the method call move(PermutationList,NewPermutationList).
Where given a permutation list as input, will produce as output a list identical to the first but in which two elements have been swapped. Through backtracking the procedure should produce all possible swaps.
e.g move([2,1],SL). SL = [1,2]
move([1,2,3],SL). SL = [2,1,3] SL = [3,2,1] SL = [1,3,2]
I have written some code which works for [2,1] but thats it.
move([],[]).
move([H,T|Rest],[T,H|Rest]):- move(Rest,Rest).
please help me |
|
[ Log in to reply ] |
|
|
Acorn Arcade forums: Programming: PROLOG Lists pleas help |