Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: $Revision: 1.6.2.13 $; site uiucdcs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!inuxc!pur-ee!uiucdcs!schang From: schang@uiucdcs.UUCP Newsgroups: net.micro.pc Subject: Re: Programing Puzzle - (nf) Message-ID: <24700048@uiucdcs.UUCP> Date: Sat, 21-Jul-84 16:57:00 EDT Article-I.D.: uiucdcs.24700048 Posted: Sat Jul 21 16:57:00 1984 Date-Received: Sun, 22-Jul-84 06:21:43 EDT References: <994@inuxc.UUCP> Lines: 49 Nf-ID: #R:inuxc:-99400:uiucdcs:24700048:000:990 Nf-From: uiucdcs!schang Jul 21 15:57:00 1984 #R:inuxc:-99400:uiucdcs:24700048:000:990 uiucdcs!schang Jul 21 15:57:00 1984 [] Prolog is probably the best language to solve this problem, it took me less than 15 minutes to write and test the following : > % 'permut' returns one permutation of 'List'. It consists of taking one > % element from 'List' and then taking one permutation of the remaining > % list. > > permut(List, [Elt | Tail]) :- > pickup_one(Elt,List,Remaining), > permut( Remaining, Tail). > permut( [], []). > > pickup_one( X, [X | T], T). > pickup_one( X, [Y | T], [Y | Z]) :- > pickup_one( X, T, Z). Here is the result of the program : > > UNSW - PROLOG (IBM PC) > : permut([1,2,3], X)? > > X = [1, 2, 3] > > X = [1, 3, 2] > > X = [2, 1, 3] > > X = [2, 3, 1] > > X = [3, 1, 2] > > X = [3, 2, 1] > : ^D Thierry Schang ...!{ihnp4, pur-ee, parsec}!uiucdcs!schang Department of Computer Science University of Illinois 1304, W. Springfield Urbana, Il 61801