<?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"
	>
<channel>
	<title>Comments on: I think my brain just exploded</title>
	<atom:link href="http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/feed/" rel="self" type="application/rss+xml" />
	<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/</link>
	<description>Robert Fischer and Brian Hurt on Punditry, Programming Languages, and Other Religious Issues</description>
	<pubDate>Mon, 08 Sep 2008 08:09:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: kshitij</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32668</link>
		<dc:creator>kshitij</dc:creator>
		<pubDate>Tue, 26 Feb 2008 10:47:17 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32668</guid>
		<description>for parselmouths:

filter(lambda (x, y, z): x*x + y*y == z*z, [(a, b, c) for a in range (1, n+1) for b in range (a, n+1) for c in range(b, n+1)])

obviously, the haskell and python versions are idea-wise isomorphic.

and here's a kind of O(n^2) version . the range for the multiplying factor (mu) is off the top of my head, and is there to take the output from the p-q stuff (eg (3,4,5)) and get the derived triplets (eg (6,8,10) and (12,16,20)). i say "kind of" O(n^2) because the generation of unique triplets is O(n^2) at minimum, and multiplying each of the integers in the triplet to get all the derived triplets is an additional operation. i don't have the upper bound for the multiplying factor, though if it can be proved that such a bound exists and is independent of n, the algorithm would become strictly -- as opposed to "kind of" -- O(n^2)

filter(lambda (a, b, c): max(a, b, c) &#60;= n, [(p*q*mu, ((p**2 - q**2)/2)*mu, ((p**2 + q**2)/2)*mu) for q in range(1,n,2) for p in range(q+2,n,2) for mu in range(1, 5)])</description>
		<content:encoded><![CDATA[<p>for parselmouths:</p>
<p>filter(lambda (x, y, z): x*x + y*y == z*z, [(a, b, c) for a in range (1, n+1) for b in range (a, n+1) for c in range(b, n+1)])</p>
<p>obviously, the haskell and python versions are idea-wise isomorphic.</p>
<p>and here&#8217;s a kind of O(n^2) version . the range for the multiplying factor (mu) is off the top of my head, and is there to take the output from the p-q stuff (eg (3,4,5)) and get the derived triplets (eg (6,8,10) and (12,16,20)). i say &#8220;kind of&#8221; O(n^2) because the generation of unique triplets is O(n^2) at minimum, and multiplying each of the integers in the triplet to get all the derived triplets is an additional operation. i don&#8217;t have the upper bound for the multiplying factor, though if it can be proved that such a bound exists and is independent of n, the algorithm would become strictly &#8212; as opposed to &#8220;kind of&#8221; &#8212; O(n^2)</p>
<p>filter(lambda (a, b, c): max(a, b, c) &lt;= n, [(p*q*mu, ((p**2 - q**2)/2)*mu, ((p**2 + q**2)/2)*mu) for q in range(1,n,2) for p in range(q+2,n,2) for mu in range(1, 5)])</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DavidLG</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32254</link>
		<dc:creator>DavidLG</dc:creator>
		<pubDate>Mon, 31 Dec 2007 10:44:37 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32254</guid>
		<description>Replying to the original post, you can do the same thing in Scala:

def f(n:Int) = for(x &#60;- 1 to n; y &#60;- (x+1) to n; z &#60;- (y+1) to n; if x*x + y*y == z*z) yield (x,y,z);

The Scala compiler infers the return type of the function, Seq[(Int,Int,Int)], and compiles the code into statically-typed JVM bytecodes.</description>
		<content:encoded><![CDATA[<p>Replying to the original post, you can do the same thing in Scala:</p>
<p>def f(n:Int) = for(x &lt;- 1 to n; y &lt;- (x+1) to n; z &lt;- (y+1) to n; if x*x + y*y == z*z) yield (x,y,z);</p>
<p>The Scala compiler infers the return type of the function, Seq[(Int,Int,Int)], and compiles the code into statically-typed JVM bytecodes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32251</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Mon, 31 Dec 2007 01:26:23 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32251</guid>
		<description>Spruce Moose: actually, I'm not working on Project Euler.  This was something different.</description>
		<content:encoded><![CDATA[<p>Spruce Moose: actually, I&#8217;m not working on Project Euler.  This was something different.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32249</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Sun, 30 Dec 2007 23:17:05 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32249</guid>
		<description>Programming is a bad choice for people who are bad in math stuff, IMHO.</description>
		<content:encoded><![CDATA[<p>Programming is a bad choice for people who are bad in math stuff, IMHO.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spruce Moose</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32248</link>
		<dc:creator>Spruce Moose</dc:creator>
		<pubDate>Sun, 30 Dec 2007 22:43:12 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32248</guid>
		<description>Oh man - spoilers for Problem 9 of Project Euler or what.  (-:  I'm working on that one at the moment, but using Erlang.</description>
		<content:encoded><![CDATA[<p>Oh man - spoilers for Problem 9 of Project Euler or what.  (-:  I&#8217;m working on that one at the moment, but using Erlang.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: she</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32243</link>
		<dc:creator>she</dc:creator>
		<pubDate>Sun, 30 Dec 2007 06:55:24 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32243</guid>
		<description>Hmm... unfortunately i am not good at math, but i hear more praise about haskell than ocaml. The question still remains however, aren't both bad choice for people who are bad in math stuff?</description>
		<content:encoded><![CDATA[<p>Hmm&#8230; unfortunately i am not good at math, but i hear more praise about haskell than ocaml. The question still remains however, aren&#8217;t both bad choice for people who are bad in math stuff?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Dubs</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32240</link>
		<dc:creator>Justin Dubs</dc:creator>
		<pubDate>Sun, 30 Dec 2007 03:24:18 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32240</guid>
		<description>Here is a slight tweak of your haskell code to make it generate ALL of the pythagorean triples, in order of hypotenuse length:

pythagoreanTriples :: [(Int, Int, Int)]
pythagoreanTriples = [(a, b, c) &#124; c &#60;- [1..], b &#60;- [1..c-1], a &#60;- [1..b-1], a^2 + b^2 == c^2]

Prelude&#62; take 5 pythagoreanTriples
[(3,4,5),(6,8,10),(5,12,13),(9,12,15),(8,15,17)]</description>
		<content:encoded><![CDATA[<p>Here is a slight tweak of your haskell code to make it generate ALL of the pythagorean triples, in order of hypotenuse length:</p>
<p>pythagoreanTriples :: [(Int, Int, Int)]<br />
pythagoreanTriples = [(a, b, c) | c &lt;- [1..], b &lt;- [1..c-1], a &lt;- [1..b-1], a^2 + b^2 == c^2]</p>
<p>Prelude&gt; take 5 pythagoreanTriples<br />
[(3,4,5),(6,8,10),(5,12,13),(9,12,15),(8,15,17)]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Dubs</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32239</link>
		<dc:creator>Justin Dubs</dc:creator>
		<pubDate>Sun, 30 Dec 2007 03:20:29 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32239</guid>
		<description>Here's a slight tweak of your haskell code to generate ALL of the pythagorean triples, in order of hypotenuse length:

pythagoreanTriples :: [(Int, Int, Int)]
pythagoreanTriples = [(a, b, c) &#124; c &#60;- [1..], b &#60;- [1..c-1], a  take 5 pythagoreanTriples
[(3,4,5),(6,8,10),(5,12,13),(9,12,15),(8,15,17)]</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a slight tweak of your haskell code to generate ALL of the pythagorean triples, in order of hypotenuse length:</p>
<p>pythagoreanTriples :: [(Int, Int, Int)]<br />
pythagoreanTriples = [(a, b, c) | c &lt;- [1..], b &lt;- [1..c-1], a  take 5 pythagoreanTriples<br />
[(3,4,5),(6,8,10),(5,12,13),(9,12,15),(8,15,17)]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ChriS</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32236</link>
		<dc:creator>ChriS</dc:creator>
		<pubDate>Sun, 30 Dec 2007 03:10:15 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32236</guid>
		<description>In passing, let me mention that the monadic version which looks quite similar too (even more so with the &lt;code&gt;do&lt;/code&gt; notation not shown here):
&lt;code&gt;
let f n =
  range 1 n &#62;&#62;= (fun x -&#62;
  range (x+1) n &#62;&#62;= (fun y -&#62;
  range (y+1) n &#62;&#62;= (fun z -&#62;
  if  x * x + y * y = z * z then return(x,y,z) else [] )))
&lt;/code&gt;
(the &lt;code&gt;&#62;&#62;=&lt;/code&gt; and &lt;code&gt;return&lt;/code&gt; are the standard monadic operators on lists — see http://enfranchisedmind.com/blog/2007/08/06/a-monad-tutorial-for-ocaml/).</description>
		<content:encoded><![CDATA[<p>In passing, let me mention that the monadic version which looks quite similar too (even more so with the <code>do</code> notation not shown here):<br />
<code><br />
let f n =<br />
  range 1 n &gt;&gt;= (fun x -&gt;<br />
  range (x+1) n &gt;&gt;= (fun y -&gt;<br />
  range (y+1) n &gt;&gt;= (fun z -&gt;<br />
  if  x * x + y * y = z * z then return(x,y,z) else [] )))<br />
</code><br />
(the <code>&gt;&gt;=</code> and <code>return</code> are the standard monadic operators on lists — see <a href="http://enfranchisedmind.com/blog/2007/08/06/a-monad-tutorial-for-ocaml/" rel="nofollow">http://enfranchisedmind.com/blog/2007/08/06/a-monad-tutorial-for-ocaml/</a>).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32235</link>
		<dc:creator>James</dc:creator>
		<pubDate>Sun, 30 Dec 2007 03:04:03 +0000</pubDate>
		<guid isPermaLink="false">http://enfranchisedmind.com/blog/2007/12/28/i-think-my-brain-just-exploded/#comment-32235</guid>
		<description>Funny, I just did this today for Project Euler (I'd already solved the problem using smarter methods than this, but I was curious as to how to do this with list comprehensions).  While it was too slow for that problem, it's great how a one-liner like this can do so much.</description>
		<content:encoded><![CDATA[<p>Funny, I just did this today for Project Euler (I&#8217;d already solved the problem using smarter methods than this, but I was curious as to how to do this with list comprehensions).  While it was too slow for that problem, it&#8217;s great how a one-liner like this can do so much.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
