<?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>#if debug &#187; project euler</title>
	<atom:link href="http://ifdebug.com/articles/tag/project-euler/feed/" rel="self" type="application/rss+xml" />
	<link>http://ifdebug.com</link>
	<description>Technical thoughts of a coffee addicted developer</description>
	<lastBuildDate>Sun, 11 Apr 2010 12:53:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Project Euler, Problem #1</title>
		<link>http://ifdebug.com/articles/project-euler-problem-1/</link>
		<comments>http://ifdebug.com/articles/project-euler-problem-1/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 21:23:21 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ifdebug.com/?p=107</guid>
		<description><![CDATA[The first problem within Project Euler isn&#8217;t meant to twist the brain in knots and is a gentle introduction to what is coming further down the road. The problem states: If we list all the natural numbers below 10 that &#8230; <a href="http://ifdebug.com/articles/project-euler-problem-1/">Continue reading <span class="meta-nav">&#8594;</span></a>


No related posts.]]></description>
			<content:encoded><![CDATA[<p>The first problem within Project Euler isn&#8217;t meant to twist the brain in knots and is a gentle introduction to what is coming further down the road. The problem states:</p>
<blockquote><p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.</p>
<p>Find the sum of all the multiples of 3 or 5 below 1000.</p></blockquote>
<p>As I mentioned in my <a href="http://ifdebug.com/articles/project-euler-an-exercise-in-exploration/">initial post about exploring Project Euler</a>, I noted that I often write in a lowest common denominator with whatever language I&#8217;m using at the time. The net effect of that decision is often a working but poorly optimised solution or a solution that doesn&#8217;t fit well with the spirit of the programming language.</p>
<p>The solution to problem #1 took three distinct evolutions, the first of which is below and looks like a solution you&#8217;d likely see in any programming language:</p>
<pre>i = 1
sum = 0

while i &lt; 1000:
  if i % 3 == 0 or i % 5 == 0:
    sum += i
  i += 1

print sum</pre>
<p>I wasn&#8217;t a fan of needing to declare the variables to start with for such a simple problem, so removed the need for the <code>i</code> but using the Python <a href="http://docs.python.org/lib/built-in-funcs.html"><code>range</code></a> function to generate a series of numbers. The <code>range</code> function allows you to generate any length series of numbers, starting and ending where you want with any stepping. By default, it starts at 0 and a stepping of 1 &#8211; which means <code>range(1000)</code> is going to generate a list of numbers from 0 &#8211; 999.</p>
<pre>sum = 0

for x in range(1000):
  if x % 3 == 0 or x % 5 == 0:
    sum += x

print sum</pre>
<p>Python provides functionality for its lists called list comprehensions. The idea behind a list comprehension is that you can perform the same action, whatever that may be, against each item in the set. In the final solution below, I have applied a filter (the <code>if</code> statements), which now only returns those items from the <code>for x in range</code> that match and I&#8217;m not applying an expression to the resulting matches (the solitary <code>x</code> before the <code>for</code>). Once collected the new list is passed to the <code>sum</code> function to yield our result.</p>
<pre>sum([x for x in range(1000) if x % 3 == 0 or x % 5 == 0])</pre>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://ifdebug.com/articles/project-euler-problem-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Project Euler, An Exercise In Exploration</title>
		<link>http://ifdebug.com/articles/project-euler-an-exercise-in-exploration/</link>
		<comments>http://ifdebug.com/articles/project-euler-an-exercise-in-exploration/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 08:42:23 +0000</pubDate>
		<dc:creator>Alistair</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ifdebug.com/?p=102</guid>
		<description><![CDATA[Some time ago I stumbled onto a math based problem solving site for programmers named Project Euler. The Project Euler site describes itself as: Project Euler is a series of challenging mathematical/computer programming problems that will require more than just &#8230; <a href="http://ifdebug.com/articles/project-euler-an-exercise-in-exploration/">Continue reading <span class="meta-nav">&#8594;</span></a>


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Some time ago I stumbled onto a math based problem solving site for programmers named <a href="http://projecteuler.net">Project Euler</a>. The Project Euler site describes itself as:</p>
<blockquote><p>Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.</p>
<p>The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.</p></blockquote>
<p>Possible solutions to the problems are verified through the Project Euler web site, where your successes are recorded if you sign up for an account. You don&#8217;t need to work through the problems in order, however doing so may be beneficial as work completed and previous questions is often reused.</p>
<p>I thought Project Euler would be a great exercise to explore more of the Python programming language. While I&#8217;ve read quite a bit about the Python language, I&#8217;ve not written anything substantial in it and I often find myself using the lowest common denominator in my approaches to solving problems as a by product.</p>
<p>My intention while working through the problems presented within Project Euler is to find a neater, cleaner method of solving the problem which is hopefully more pythonic. I&#8217;ll present my solution to the problems and with a little luck, I&#8217;ll receive some helpful improvements from the great programming community as well.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://ifdebug.com/articles/project-euler-an-exercise-in-exploration/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
