<?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; Fibonacci Numbers</title>
	<atom:link href="http://blog.dreamshire.com/tag/fibonacci-numbers/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>
		<item>
		<title>Project Euler Problem 25 Solution</title>
		<link>http://blog.dreamshire.com/2009/04/10/project-euler-problem-25-solution/</link>
		<comments>http://blog.dreamshire.com/2009/04/10/project-euler-problem-25-solution/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 04:07:27 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Project Euler Solutions]]></category>
		<category><![CDATA[Solutions 20-29]]></category>
		<category><![CDATA[Fibonacci Numbers]]></category>
		<category><![CDATA[Large Integers]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.dreamshire.com/?p=577</guid>
		<description><![CDATA[What is the first term in the Fibonacci sequence to contain 1000 digits?]]></description>
			<content:encoded><![CDATA[<h4><u>Problem Description</u></h4>
<p>The Fibonacci sequence is defined by the recurrence relation:</p>
<p>F<sub><i>n</i></sub> = F<sub><i>n</i>&minus;1</sub> + F<sub><i>n</i>&minus;2</sub>, where F<sub>1</sub> = 1 and F<sub>2</sub> = 1.</p>
<p>Hence the first 12 terms will be:</p>
<table>
<tr>
<td>
F<sub>1</sub> = 1<br />
F<sub>2</sub> = 1<br />
F<sub>3</sub> = 2<br />
F<sub>4</sub> = 3<br />
F<sub>5</sub> = 5<br />
F<sub>6</sub> = 8
</td>
<td colspan=7></td>
<td>
F<sub>7</sub> = 13<br />
F<sub>8</sub> = 21<br />
F<sub>9</sub> = 34<br />
F<sub>10</sub> = 55<br />
F<sub>11</sub> = 89<br />
F<sub>12</sub> = 144
</td>
</tr>
</table>
<p>The 12th term, F<sub>12</sub>, is the first term to contain three digits.</p>
<p>What is the first term in the Fibonacci sequence to contain 1000 digits?</p>
<h4><u>Analysis</u></h4>
<p>Solving this problem simply comes down to knowing <a href="http://mathworld.wolfram.com/BinetsFibonacciNumberFormula.html">Binet&#8217;s formula</a> for finding the nth Fibonacci term and using logs to determine its magnitude.  This formula takes advantage of Fibonacci terms converging to (n)*Phi = (n+1), where Phi is the Golden Ratio (1 + &radic;5)/2.<br />
In order to find the index, <em>n</em>, of a Fibonacci number, f<sub>n</sub> with <em>d</em> digits:</p>
<p><em>n</em> in f<sub>n</sub> = (<em>d</em> &minus; 1 + log<sub>10</sub>(5) /2) / log<sub>10</sub>(phi)</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;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">math</span> <span style="color: #ff7700;font-weight:bold;">import</span> log10, ceil, sqrt
phi = <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>+sqrt<span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span> 
digits = <span style="color: #ff4500;">1000</span>
&nbsp;
f_term = ceil<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>digits-<span style="color: #ff4500;">1</span> + log10<span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> / log10<span style="color: black;">&#40;</span>phi<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Answer to PE25 = &quot;</span>, <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>f_term<span style="color: black;">&#41;</span></pre></div></div>

<h4><u>Comments</u></h4>
<ul>
<li>Binet&#8217;s Fibonacci Formula<br />
<img src="http://mathworld.wolfram.com/images/equations/BinetsFibonacciNumberFormula/NumberedEquation1.gif" alt="Binet's Fibonacci Number Formula" /></li>
<li>Works for digits > 1</li>
<li>Did you know that you can use the Fibonacci sequence to convert between miles and kilometers?  Just find the miles in the sequence and take the next value in the sequence for an approximate measure in kilometers.  For example, 89 miles is approximately 144 kilometers. </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.dreamshire.com/2009/04/10/project-euler-problem-25-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
