<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Calculating Combinations the Erlang Way</title>
	<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/</link>
	<description>Semantic Web, Ruby on Rails, and Massive Data</description>
	<pubDate>Fri, 21 Nov 2008 03:51:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>

	<item>
		<title>By: Semergence &#187; Blog Archive &#187; Calculating Combinations Using Java and Lots of Bits</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-748</link>
		<dc:creator>Semergence &#187; Blog Archive &#187; Calculating Combinations Using Java and Lots of Bits</dc:creator>
		<pubDate>Wed, 22 Oct 2008 02:32:58 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-748</guid>
		<description>[...] was feeling nostalgic and went back to see how I calculated combinations in Erlang and combinations in Ruby. I wanted to see if there was an efficient way to do it without resorting [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] was feeling nostalgic and went back to see how I calculated combinations in Erlang and combinations in Ruby. I wanted to see if there was an efficient way to do it without resorting [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Mercer</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-209</link>
		<dc:creator>David Mercer</dc:creator>
		<pubDate>Mon, 06 Aug 2007 15:20:11 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-209</guid>
		<description>&lt;p&gt;I might be wrong here, but I think listing the combinations of any more than, say, 20 elements is unreasonable.  There are 1,048,576 combinations of 20 elements.  Your example of 100 elements would produce a list of length 1,267,650,600,228,229,401,496,703,205,376 elements (each element being itself a list of 0–100 elements).  I don't know the statistics on the amount of memory in the world (or the number of electrons in the universe), but I am guessing that is much larger than any memory in the universe can hold.&lt;/p&gt;

&lt;p&gt;For that reason, worrying whether the function is tail-recursive is probably not important, since you're not going to have that many levels of recursion.  If you do manage to procure enough memory to run the calculation, the stack space taken up by the recursion is insignificant next to the memory requirements of your result.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>I might be wrong here, but I think listing the combinations of any more than, say, 20 elements is unreasonable.  There are 1,048,576 combinations of 20 elements.  Your example of 100 elements would produce a list of length 1,267,650,600,228,229,401,496,703,205,376 elements (each element being itself a list of 0–100 elements).  I don&#8217;t know the statistics on the amount of memory in the world (or the number of electrons in the universe), but I am guessing that is much larger than any memory in the universe can hold.</p>
<p>For that reason, worrying whether the function is tail-recursive is probably not important, since you&#8217;re not going to have that many levels of recursion.  If you do manage to procure enough memory to run the calculation, the stack space taken up by the recursion is insignificant next to the memory requirements of your result.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Munat</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-208</link>
		<dc:creator>Ben Munat</dc:creator>
		<pubDate>Sun, 05 Aug 2007 20:23:21 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-208</guid>
		<description>&lt;p&gt;Wow, I didn't think it was possible to get it &lt;em&gt;that&lt;/em&gt; (@Jason/David) compact. In my aborted attempt, I was trying the "local function with accumulator" approach. I need to work on my list comprehension mojo... seems very powerful indeed.&lt;/p&gt;

&lt;p&gt;One question though: is the solution here tail recursive? If I'm understanding it right, I don't think it is... process() is called recursively with the tail, and then as these calls exit, the results are used by the list comprehension and passed to append.&lt;/p&gt;

&lt;p&gt;To test my theory out, I figured I'd see how it does with a bit longer list.... like, uh, a hundred or so elements. The answer is "don't do that"... it makes your computer very very unhappy. :-)&lt;/p&gt;

&lt;p&gt;So, anyone have another version -- even if it's not quite so compact -- that isn't a potential DOS?&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Wow, I didn&#8217;t think it was possible to get it <em>that</em> (@Jason/David) compact. In my aborted attempt, I was trying the &#8220;local function with accumulator&#8221; approach. I need to work on my list comprehension mojo&#8230; seems very powerful indeed.</p>
<p>One question though: is the solution here tail recursive? If I&#8217;m understanding it right, I don&#8217;t think it is&#8230; process() is called recursively with the tail, and then as these calls exit, the results are used by the list comprehension and passed to append.</p>
<p>To test my theory out, I figured I&#8217;d see how it does with a bit longer list&#8230;. like, uh, a hundred or so elements. The answer is &#8220;don&#8217;t do that&#8221;&#8230; it makes your computer very very unhappy. <img src='http://www.semergence.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>So, anyone have another version &#8212; even if it&#8217;s not quite so compact &#8212; that isn&#8217;t a potential DOS?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Semergence &#187; Blog Archive &#187; Calculating Combinations In Ruby From Erlang</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-207</link>
		<dc:creator>Semergence &#187; Blog Archive &#187; Calculating Combinations In Ruby From Erlang</dc:creator>
		<pubDate>Sun, 05 Aug 2007 07:53:59 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-207</guid>
		<description>&lt;p&gt;[...] thanks to the many people (here and here) that provided their versions of an erlang way to calculate combinations, I&#8217;ve [...]&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>[&#8230;] thanks to the many people (here and here) that provided their versions of an erlang way to calculate combinations, I&#8217;ve [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Mercer</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-206</link>
		<dc:creator>David Mercer</dc:creator>
		<pubDate>Fri, 03 Aug 2007 19:17:00 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-206</guid>
		<description>&lt;p&gt;This one's a higher golf score (50), but much more efficient, since it only calls itself once.  Thanks to Jason's comment above for the idea.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;c([])-&#62;[[]];c([H&#124;T])-&#62;[G++C&#124;&#124;G&#60;-[[H],[]],C&#60;-c(T)].
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>This one&#8217;s a higher golf score (50), but much more efficient, since it only calls itself once.  Thanks to Jason&#8217;s comment above for the idea.</p>
<pre><code>c([])-&gt;[[]];c([H|T])-&gt;[G++C||G&lt;-[[H],[]],C&lt;-c(T)].
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: sethladd</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-205</link>
		<dc:creator>sethladd</dc:creator>
		<pubDate>Fri, 03 Aug 2007 19:15:01 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-205</guid>
		<description>&lt;p&gt;Jason, I bow down to you, sir.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Jason, I bow down to you, sir.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sethladd</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-204</link>
		<dc:creator>sethladd</dc:creator>
		<pubDate>Fri, 03 Aug 2007 19:11:58 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-204</guid>
		<description>&lt;p&gt;David, looking good!  I've read that using ++ like that is bad form.  Of course, as an erlang n00b, what do I know? :)&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>David, looking good!  I&#8217;ve read that using ++ like that is bad form.  Of course, as an erlang n00b, what do I know? <img src='http://www.semergence.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Mercer</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-203</link>
		<dc:creator>David Mercer</dc:creator>
		<pubDate>Fri, 03 Aug 2007 19:05:38 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-203</guid>
		<description>&lt;p&gt;OK, thanks to Masonium's comment, I have now managed to golf this problem down to 45 characters, and I don't even need the mask/1 function I defined earlier but then didn't count against my score.  Here is the all-in-one combination generator function:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;c([])-&#62;[[]];c([H&#124;T])-&#62;[[H&#124;C]&#124;&#124;C&#60;-c(T)]++c(T).
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>OK, thanks to Masonium&#8217;s comment, I have now managed to golf this problem down to 45 characters, and I don&#8217;t even need the mask/1 function I defined earlier but then didn&#8217;t count against my score.  Here is the all-in-one combination generator function:</p>
<pre><code>c([])-&gt;[[]];c([H|T])-&gt;[[H|C]||C&lt;-c(T)]++c(T).
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-202</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Fri, 03 Aug 2007 19:00:53 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-202</guid>
		<description>&lt;p&gt;combos([]) -&#62;
    [[]];
combos([H&#124;T]) -&#62;
    lists:append([[[H&#124;L],L] &#124;&#124; L &#60;- combos(T)]).&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>combos([]) -&gt;<br />
    [[]];<br />
combos([H|T]) -&gt;<br />
    lists:append([[[H|L],L] || L &lt;- combos(T)]).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Mercer</title>
		<link>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-201</link>
		<dc:creator>David Mercer</dc:creator>
		<pubDate>Fri, 03 Aug 2007 18:54:04 +0000</pubDate>
		<guid>http://www.semergence.com/2007/08/01/calculating-combinations-the-erlang-way/#comment-201</guid>
		<description>&lt;p&gt;I sat there and looked at that filter, sure that there was a shorter way to do it, but couldn't figure it out.  Soon after I posted, I read http://weblog.hypotheticalabs.com/?p=137, which explained that list comprehensions can be used for filtering, too.  Using those techniques, I have my golf score down to 66:&lt;/p&gt;

&lt;p&gt;c(L)-&#62;[[V&#124;&#124;{V,true}&#60;-C]&#124;&#124;C&#60;-[lists:zip(L,M)&#124;&#124;M&#60;-mask(length(L))]].&lt;/p&gt;

&lt;p&gt;Of course, this still relies on my definition of mask/1, which I'm not counting against me.  Masonium's post above, though, gives me some ideas.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>I sat there and looked at that filter, sure that there was a shorter way to do it, but couldn&#8217;t figure it out.  Soon after I posted, I read <a href="http://weblog.hypotheticalabs.com/?p=137," rel="nofollow">http://weblog.hypotheticalabs.com/?p=137,</a> which explained that list comprehensions can be used for filtering, too.  Using those techniques, I have my golf score down to 66:</p>
<p>c(L)-&gt;[[V||{V,true}&lt;-C]||C&lt;-[lists:zip(L,M)||M&lt;-mask(length(L))]].</p>
<p>Of course, this still relies on my definition of mask/1, which I&#8217;m not counting against me.  Masonium&#8217;s post above, though, gives me some ideas.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
