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
- Elsear brings super-fast Networking to Risc PC/A7000/A7000+ (News:)
- Latest hardware upgrade from RISCOSbits (News:)
- Announcing the TIB 2024 Advent Calendar (News:1)
- Code GCC produces that makes you cry #12684 (Prog:39)
- RISCOSbits releases a new laptop solution (News:)
- Rougol November 2024 meeting on monday (News:)
- Drag'n'Drop 14i1 edition reviewed (News:)
- WROCC November 2024 talk o...ay - Andrew Rawnsley (ROD) (News:2)
- October 2024 News Summary (News:3)
- RISC OS London Show Report 2024 (News:1)
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