From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.help Subject: Re: All Possible Combinations Date: Wed, 3 Jun 2009 11:55:55 +0200 Message-ID: References: <778c22e3-3233-4cec-899e-c9f77208155a@z14g2000yqa.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1244022995 9306 80.91.229.12 (3 Jun 2009 09:56:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 3 Jun 2009 09:56:35 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: =?UTF-8?B?Tm9yZGzDtnc=?= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jun 03 11:56:33 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MBnCw-0003Sx-Jd for geh-help-gnu-emacs@m.gmane.org; Wed, 03 Jun 2009 11:56:30 +0200 Original-Received: from localhost ([127.0.0.1]:35742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBnCw-0003Ha-5S for geh-help-gnu-emacs@m.gmane.org; Wed, 03 Jun 2009 05:56:30 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MBnCU-0003H6-Kl for help-gnu-emacs@gnu.org; Wed, 03 Jun 2009 05:56:02 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MBnCQ-0003GS-BW for help-gnu-emacs@gnu.org; Wed, 03 Jun 2009 05:56:02 -0400 Original-Received: from [199.232.76.173] (port=39152 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBnCP-0003GH-Oq for help-gnu-emacs@gnu.org; Wed, 03 Jun 2009 05:55:58 -0400 Original-Received: from mail-bw0-f161.google.com ([209.85.218.161]:47226) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MBnCO-0006KU-IK for help-gnu-emacs@gnu.org; Wed, 03 Jun 2009 05:55:57 -0400 Original-Received: by bwz5 with SMTP id 5so9518233bwz.42 for ; Wed, 03 Jun 2009 02:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=G9/D7CfsOhSiA5siVLYBe1gP8wsp852Y6UDnpi5sifw=; b=DFRm21LurTBZ6Iy12moUG93ts7t0uaa1VkEg4wIYbfG5F9ji1B+ndlo5ZqOxgij7Yy 4zET4MDNM1owQzymvxRrr8YGQ0iDUC/FAfJj/ep2xi8LARBXUt0O5pCHP1G1DrGpZELZ 4xfaYQQA5xvI1lUBDBAaMRH8vjeMQq4YY4zbs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=HYiDwmWyhp8URKDinqHAHXwRov+ZVi3IOP6Br44DvXdMNFTalY4CfK3U/jXDzUVmmD uJ1BW9woz/cWJspwnNaHvdPAS1o6RiO8zfL2hZ/6j2be/D0CwhfAOoRriuznD5pst6yE NNpe1fLInQ+dyrj9PufA+kml43gJXcpbez7cU= Original-Received: by 10.239.150.144 with SMTP id n16mr52781hbb.132.1244022955238; Wed, 03 Jun 2009 02:55:55 -0700 (PDT) In-Reply-To: <778c22e3-3233-4cec-899e-c9f77208155a@z14g2000yqa.googlegroups.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:64915 Archived-At: On Wed, Jun 3, 2009 at 11:09 AM, Nordl=C3=B6w wrote= : > Hey! > > I want a function that generates all possible combinations (ordering) > of the elements in a list (or sequence if possible). Here is my > mockup: > > (defun all-combinations (n) > =C2=A0"Generate a listing of all the possible combinations of the > elements in the sequence N. Time-Complexity is N!" > =C2=A0(let (all) > =C2=A0 =C2=A0all)) > > For example (all-combinations '(a b c)) should return '((a b c) (a c > b) (b a c) (b c a) (c a b) (c b a)) > > Has somebody written such a function, preferrably in an iterative > rather than recursive way. Would not that require building a stack to keep track of state just as recursion would do internally?