log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- Archive Edition 27:2 reviewed (News:)
- WROCC May 2024 meeting - Gerph talks games (News:)
- Drag'n'Drop 13i3 edition reviewed (News:1)
- Wakefield Show 2024 in Pictures (News:5)
- April 2024 News Summary (News:2)
- RISC OS 5.30 arrives (News:2)
- Upgrading your RISC OS system to 5.30 (News:2)
- WROCC May 2024 meeting on wednesday - Gerph talks games (News:)
- uniprint upgraded to 4.50 (News:)
- PhotoDesk 3.23 released (News:)
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
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