<?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>Dreamshire &#187; Golden Ratio</title>
	<atom:link href="http://blog.dreamshire.com/tag/golden-ratio/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dreamshire.com</link>
	<description>Showing what's behind the curtain</description>
	<lastBuildDate>Wed, 01 Sep 2010 02:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Project Euler Problem 2 Solution</title>
		<link>http://blog.dreamshire.com/2009/05/17/project-euler-problem-2-solution/</link>
		<comments>http://blog.dreamshire.com/2009/05/17/project-euler-problem-2-solution/#comments</comments>
		<pubDate>Mon, 18 May 2009 01:55:24 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Project Euler Solutions]]></category>
		<category><![CDATA[Solutions 1-9]]></category>
		<category><![CDATA[Fibonacci Numbers]]></category>
		<category><![CDATA[Golden Ratio]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.dreamshire.com/?p=1241</guid>
		<description><![CDATA[Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million.]]></description>
			<content:encoded><![CDATA[<h4><u>Problem Description</u></h4>
<p>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:</p>
<p style='text-align:center;'>1, 2, 3, 5, 8, 13, 21, 34, 55, 89, &#8230;</p>
<p>Find the sum of all the even-valued terms in the sequence which do not exceed four million.</p>
<h4><u>Analysis</u></h4>
<p>The approximate ratio between two consecutive terms in the Fibonacci sequence is the <a href="http://en.wikipedia.org/wiki/Golden_ratio">golden ratio</a> (phi, or φ &asymp; 1.618034).  It can also be demonstrated that every 3rd term of the sequence is even.  By combining this knowledge we can calculate the series of even Fibonacci numbers by multiplying the previous even term in the series by the cube of the golden ratio.</p>
<h4><u>Solution</u></h4>
<p>Runs < 1 second in Python.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">limit = <span style="color: #ff4500;">4000000</span>
phi_cubed = <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>+<span style="color: #ff4500;">5</span><span style="color: #66cc66;">**</span>.5<span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">**</span><span style="color: #ff4500;">3</span>   <span style="color: #808080; font-style: italic;">#golden ratio cubed</span>
&nbsp;
f = <span style="color: #ff4500;">2</span>
<span style="color: #008000;">sum</span> = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">while</span> f <span style="color: #66cc66;">&lt;</span> limit:
  <span style="color: #008000;">sum</span> += f
  f = <span style="color: #008000;">round</span><span style="color: black;">&#40;</span>f<span style="color: #66cc66;">*</span>phi_cubed<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Answewr to PE2 - &quot;</span>,<span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">sum</span><span style="color: black;">&#41;</span></pre></div></div>

<h4><u>Comments</u></h4>
<p>For a limit of 4,000,000 the loop iterates 10 times.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dreamshire.com/2009/05/17/project-euler-problem-2-solution/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
