<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: All combinations of N elements</title>
	<atom:link href="http://blog.labix.org/2005/04/08/all-combinations-of-n-elements/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.labix.org/2005/04/08/all-combinations-of-n-elements</link>
	<description>by Gustavo Niemeyer</description>
	<lastBuildDate>Mon, 16 Jan 2012 12:12:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Anonymous</title>
		<link>http://blog.labix.org/2005/04/08/all-combinations-of-n-elements/comment-page-1#comment-46</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 12 Apr 2005 14:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.labix.org/2005/04/08/all-combinations-of-n-elements/#comment-46</guid>
		<description>This list is the sum of three cartesian products,
here it is cheating a bit and not in exactly the same order.

&lt;pre&gt;
import probstat # probstat.sf.net
def total(mylist):
  for (n) in range(len(mylist)):
    for (item) in probstat.Cartesian([mylist]*(n+1)):
      yield item
&lt;/pre&gt;

for the list [1,2,3] it does the cartesian product of [1,2,3]
then [1,2,3] x [1,2,3] then [1,2,3] x [1,2,3] x [1,2,3]</description>
		<content:encoded><![CDATA[<p>This list is the sum of three cartesian products,<br />
here it is cheating a bit and not in exactly the same order.</p>
<pre>
import probstat # probstat.sf.net
def total(mylist):
  for (n) in range(len(mylist)):
    for (item) in probstat.Cartesian([mylist]*(n+1)):
      yield item
</pre>
<p>for the list [1,2,3] it does the cartesian product of [1,2,3]<br />
then [1,2,3] x [1,2,3] then [1,2,3] x [1,2,3] x [1,2,3]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gustavo Niemeyer</title>
		<link>http://blog.labix.org/2005/04/08/all-combinations-of-n-elements/comment-page-1#comment-45</link>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		<pubDate>Mon, 11 Apr 2005 22:06:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.labix.org/2005/04/08/all-combinations-of-n-elements/#comment-45</guid>
		<description>Hello Guyon! I think I understand what you meant now. The algorithm is pretty much the same:

&lt;pre&gt;
def allcombinations(n):
    queue = [-1]
    while queue:
        i = queue[-1]+1
        if i == 26:
            queue.pop()
        else:
            queue[-1] = i
            yield [chr(97+j) for j in queue]
            if len(queue) &lt; n:
                queue.append(-1)
&lt;/pre&gt;

The total combinations is computed by:

&lt;pre&gt;
def total(n):
    return sum([26**i for i in range(1,n+1)])
&lt;/pre&gt;

Which means 12356630 entries for n=5!!! Be careful. :-)</description>
		<content:encoded><![CDATA[<p>Hello Guyon! I think I understand what you meant now. The algorithm is pretty much the same:</p>
<pre>
def allcombinations(n):
    queue = [-1]
    while queue:
        i = queue[-1]+1
        if i == 26:
            queue.pop()
        else:
            queue[-1] = i
            yield [chr(97+j) for j in queue]
            if len(queue) < n:
                queue.append(-1)
</pre>
<p>The total combinations is computed by:</p>
</pre>
<pre>
def total(n):
    return sum([26**i for i in range(1,n+1)])
</pre>
<p>Which means 12356630 entries for n=5!!! Be careful. <img src='http://blog.labix.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guyon Moree</title>
		<link>http://blog.labix.org/2005/04/08/all-combinations-of-n-elements/comment-page-1#comment-44</link>
		<dc:creator>Guyon Moree</dc:creator>
		<pubDate>Mon, 11 Apr 2005 05:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.labix.org/2005/04/08/all-combinations-of-n-elements/#comment-44</guid>
		<description>hey, that someone was me! thanks for the code.

I don&#039;t see a &#039;border&#039; though ;)

What I mean is that you take the border from the length of your list. At least that is what I think I see happening here.

What I meant was having a list of possible characters like [&#039;a&#039;,&#039;b&#039;,(..) &#039;z&#039;]. And then also give a &#039;border&#039;. Let&#039;s say you give a border of 3. This will effectively give you all possible 3-character combinations of *all* given characters.

I hope I explained this good enough, thanks again!</description>
		<content:encoded><![CDATA[<p>hey, that someone was me! thanks for the code.</p>
<p>I don&#8217;t see a &#8216;border&#8217; though <img src='http://blog.labix.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>What I mean is that you take the border from the length of your list. At least that is what I think I see happening here.</p>
<p>What I meant was having a list of possible characters like ['a','b',(..) 'z']. And then also give a &#8216;border&#8217;. Let&#8217;s say you give a border of 3. This will effectively give you all possible 3-character combinations of *all* given characters.</p>
<p>I hope I explained this good enough, thanks again!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

