Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!hookup!jussieu.fr!univ-lyon1.fr!in2p3.fr!swidir.switch.ch!swsbe6.switch.ch!surfnet.nl!newshost.vu.nl!cs.vu.nl!sun4nl!aie.nl!news
From: geert@michelv.aie.nl (Geert-Jan van Opdorp)
Subject: Re: permutation
Sender: news@aie.nl (Usenet News)
Message-ID: <GEERT.96Feb1104956@michelv.aie.nl>
In-Reply-To: so@brownie.cs.wisc.edu's message of 30 Jan 1996 23:22:15 GMT
Date: Thu, 1 Feb 1996 09:49:55 GMT
Lines: 35
X-Nntp-Posting-Host: michelv.aie.nl
References: <4em977$osl@spool.cs.wisc.edu>
Organization: AI Engineering BV, Amsterdam, Netherlands

In article <4em977$osl@spool.cs.wisc.edu> so@brownie.cs.wisc.edu (Bryan So) writes:

> From: so@brownie.cs.wisc.edu (Bryan So)
> Newsgroups: comp.lang.lisp
> Date: 30 Jan 1996 23:22:15 GMT
> Organization: U of Wisconsin CS Dept
> 
> I wonder if anyone has what they think is the simplest, shortest
> implementation of "permutation" that can share with me.  e.g.,
> 
>    > (permute '(1 2 3))
>    ((1 3 2) (3 1 2) (3 2 1) (1 2 3) (2 1 3) (2 3 1))
> 
> Mine is about 20 lines with 3 functions... really not clever.
> Thanks.
> 
> Bryan

This is somewhat shorter, but I paid no
attention to efficiency:

(defun permute (l)
    (if (null l) ; I don't like this. I suspect that there is a more
	'(nil)   ; natural way to make the function return '(nil) for nil.
      (mapcan #'(lambda (e)
		  (mapcar #'(lambda (p) (cons e p))
			  (permute (remove e l))))
	      l)))

Geert-Jan
-- 
Geert-Jan van Opdorp
AI-Engineering
Amsterdam, The Netherlands
geert@aie.nl
