<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gonium.net &#187; codekata</title>
	<atom:link href="http://gonium.net/md/tag/codekata/feed/" rel="self" type="application/rss+xml" />
	<link>http://gonium.net/md</link>
	<description>so much time, so little to do.</description>
	<lastBuildDate>Fri, 30 Jul 2010 13:47:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code Kata: Project Euler #7, Finding Primes</title>
		<link>http://gonium.net/md/2008/09/08/code-kata-project-euler-7-finding-primes/</link>
		<comments>http://gonium.net/md/2008/09/08/code-kata-project-euler-7-finding-primes/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 08:08:52 +0000</pubDate>
		<dc:creator>md</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[nerdism]]></category>
		<category><![CDATA[codekata]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[primes]]></category>
		<category><![CDATA[projecteuler]]></category>

		<guid isPermaLink="false">http://gonium.net/md/?p=100</guid>
		<description><![CDATA[
I resumed my code katas &#8211; this time, I&#8217;m using Erlang to solve the problem:

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10001st prime number?


It seems to be clever to have a prime number generator for Project Euler [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://gonium.net/md/wp-content/uploads/2008/09/338443480_8127cdd845_o.jpg" alt="" title="Ulam_Spiral" width="500" height="333" class="alignnone size-full wp-image-101" /></p>
<p>I resumed my code katas &#8211; this time, I&#8217;m using Erlang to solve the problem:</p>
<blockquote><p>
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.<br />
What is the 10001st prime number?
</p></blockquote>
<p><span id="more-100"></span></p>
<p>It seems to be clever to have a prime number generator for Project Euler anyway. My implementation is based on the <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">Sieve of Erathosthenes</a> and uses the <a href="http://mathworld.wolfram.com/PrimeNumberTheorem.html">Prime Number Theorem</a> for an estimate on the size of the sieve. The code is pretty easy:</p>
<p class="vci_info">[viewcode]src=pe7.erl [/viewcode]</p>
<pre class="vci_code"></pre>
<p class="vci_info">HTML code generated by <a href="http://www.zacharyfox.com/blog/free-tools/vim-color-improved">vim-color-improved v.0.4.0.</a><strong>Download this code:</strong> <a href="http://gonium.net/media//pe7.erl">pe7.erl</a></p>
<p>In the erathosthenes function, a list comprehension is used to purge all multiplies of the current Index value. My first attempt didn&#8217;t include the Index variable &#8211; I simply decreased the boundary. The disadvantage of this method is that it keeps the list of primes bigger over the runtime: Instead of removing the multiples of 2 at the very beginning, they get removed as the last multiples. The size of PurgedNumbers stays bigger, which leads to a runtime of 6.7 seconds. When I use the Index variable, the multiples of 2 get removed first which avoids copying them all the way. The runtime decreases to 1.2 seconds (on my Mac Mini).</p>
<p>Since all variables in Erlang are bound only once, I don&#8217;t know how to optimize this further. In C, I would use a bit array to further reduce the memory footprint. But: the Erlang code is much easier to read and write. I think Erlang is just not made for low memory bandwidth requirements :-)</p>
<p>The picture above is an representation of the <a href="http://en.wikipedia.org/wiki/Ulam_spiral">Ulam spiral</a>, CCed on flickr by <a href="http://flickr.com/photos/kusamakura/338443480/">no_typographic_man</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://gonium.net/md/2008/09/08/code-kata-project-euler-7-finding-primes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
