<?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>Serabe Reloaded &#187; euler project</title>
	<atom:link href="http://www.serabe.com/tag/euler-project/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.serabe.com</link>
	<description>Conecto ergo sum. Non conecto ergo urgueo.</description>
	<lastBuildDate>Sun, 09 Oct 2011 21:30:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Problem 3</title>
		<link>http://www.serabe.com/2008/10/12/problem-3/</link>
		<comments>http://www.serabe.com/2008/10/12/problem-3/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 14:13:42 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Maths]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RubyEuler]]></category>
		<category><![CDATA[euler project]]></category>
		<category><![CDATA[problem 3]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[RbEuler]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=259</guid>
		<description><![CDATA[Wording: (Original) The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Solution: First the code: PLAIN TEXT RUBY: include Math def prime_factors&#40;num, factor=2&#41; &#160; return &#91;&#93;&#160; if num &#60;= 1 &#160; next_pf = &#40;factor..&#40;sqrt&#40;num&#41;.ceil&#41;&#41;.find&#40;lambda &#123;num&#125;&#41;&#123; &#124;x&#124; num%x == 0 &#125; &#160; return [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Wording:</strong> (<a href="http://projecteuler.net/index.php?section=problems&#038;id=3"  title="Project Euler">Original</a>) The prime factors of 13195 are 5, 7, 13 and 29.<br />
What is the largest prime factor of the number 600851475143 ?</p>
<p><strong>Solution:</strong><br />
First the code:</p>
<div class="igBar"><span id="lruby-2"><a href="#" onclick="javascript:showPlainTxt('ruby-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-2">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">include</span> Math</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> prime_factors<span style="color:#006600; font-weight:bold;">&#40;</span>num, factor=<span style="color:#006666;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> num &lt;= <span style="color:#006666;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; next_pf = <span style="color:#006600; font-weight:bold;">&#40;</span>factor..<span style="color:#006600; font-weight:bold;">&#40;</span>sqrt<span style="color:#006600; font-weight:bold;">&#40;</span>num<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">ceil</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span>num<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> |x| num%x == <span style="color:#006666;color:#800000;">0</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006600; font-weight:bold;">&#91;</span>next_pf<span style="color:#006600; font-weight:bold;">&#93;</span> + prime_factors<span style="color:#006600; font-weight:bold;">&#40;</span>num/next_pf, next_pf<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">puts</span> prime_factors<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">600851475143</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">max</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The code is a direct port from the one in PyEuler. It is based mainly in the idea that the first factor of a number is always prime.</p>
<p>Line 3 breaks recursion and line 4 works out the next prime factor (actually, it finds the smallest factor). For doing this, it uses find method. If no element match the criteria, then it returns the number (that is what the lambda block is for).</p>
<p>Finally, line 5 merges the results and line 8 print the result.</p>
<p>This time just one code is showed.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Problem 3 on Serabe Reloaded',url: 'http://www.serabe.com/2008/10/12/problem-3/',contentID: 'post-259',suggestTags: 'euler project,problem 3,programming,RbEuler,Ruby',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Problem 3" alt="article clipper Problem 3" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.serabe.com%2F2008%2F10%2F12%2Fproblem-3%2F&amp;title=Problem%203" id="wpa2a_2"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="share save 171 16 Problem 3"  title="Problem 3" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/10/12/problem-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problema 2</title>
		<link>http://www.serabe.com/2008/03/23/problema-2/</link>
		<comments>http://www.serabe.com/2008/03/23/problema-2/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 21:37:14 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Maths]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RubyEuler]]></category>
		<category><![CDATA[euler project]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[RbEuler]]></category>

		<guid isPermaLink="false">http://www.serabe.com/2008/03/23/problema-2/</guid>
		<description><![CDATA[Enunciado: Suma todos los nÃºmeros pares de la sucesiÃ³n de Fibonacci menores que un cuatro millÃ³n. Primera soluciÃ³n: La primera soluciÃ³n es muy simple. Hay un mÃ©todo que devuelve un array con todos los nÃºmeros de la sucesiÃ³n de Fibonacci menores que un mÃ¡ximo max tomando como inicio un array de dos elementos arr. PLAIN [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Enunciado:</strong><br />
Suma todos los nÃºmeros pares de la sucesiÃ³n de Fibonacci menores que un <em>cuatro</em> millÃ³n.</p>
<p><strong>Primera soluciÃ³n:</strong></p>
<p>La primera soluciÃ³n es muy simple. Hay un mÃ©todo que devuelve un array con todos los nÃºmeros de la sucesiÃ³n de Fibonacci menores que un mÃ¡ximo <em>max</em> tomando como inicio un array de dos elementos <em>arr</em>.</p>
<div class="igBar"><span id="lruby-8"><a href="#" onclick="javascript:showPlainTxt('ruby-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-8">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> fib1<span style="color:#006600; font-weight:bold;">&#40;</span>max,arr=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">1</span>,<span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span>arr.<span style="color:#9900CC;">last</span> &lt;max<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; arr &lt;&lt;<span style="color:#006600; font-weight:bold;">&#40;</span>arr.<span style="color:#9900CC;">last</span>+arr<span style="color:#006600; font-weight:bold;">&#91;</span>arr.<span style="color:#9900CC;">size</span>-<span style="color:#006666;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; arr.<span style="color:#9900CC;">pop</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; arr</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>DespuÃ©s simplemente se eliminan los impares y se suman los que quedan.</p>
<div class="igBar"><span id="lruby-9"><a href="#" onclick="javascript:showPlainTxt('ruby-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-9">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> euler2a<span style="color:#006600; font-weight:bold;">&#40;</span>max, ini=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">1</span>,<span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; fib1<span style="color:#006600; font-weight:bold;">&#40;</span>max,ini<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">delete_if</span><span style="color:#006600; font-weight:bold;">&#123;</span>|x| x%<span style="color:#006666;color:#800000;">2</span> == <span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#123;</span>|memo,obj| memo+obj<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">puts</span> euler2a<span style="color:#006600; font-weight:bold;">&#40;</span>4e6<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Segunda soluciÃ³n:</strong></p>
<p>Esta soluciÃ³n es un poco mejor. Se va a hacer un nuevo mÃ©todo que calcule todos los nÃºmeros de la sucesiÃ³n de Fibonacci menores que un mÃ¡ximo <strong>max</strong> pero que sÃ³lo almacene aquellos que pasen una condiciÃ³n que se le pasa como bloque:</p>
<div class="igBar"><span id="lruby-10"><a href="#" onclick="javascript:showPlainTxt('ruby-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-10">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> fib2<span style="color:#006600; font-weight:bold;">&#40;</span>max,a=<span style="color:#006666;color:#800000;">1</span>,b=<span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; arr = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; arr &lt;&lt;a <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">yield</span><span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span>b&lt;max<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; arr &lt;&lt;b <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">yield</span><span style="color:#006600; font-weight:bold;">&#40;</span>b<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; a,b=b,a+b</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; arr</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>DespuÃ©s sÃ³lo hace falta pasar el filtro adecuado, y sumar los resultados:</p>
<div class="igBar"><span id="lruby-11"><a href="#" onclick="javascript:showPlainTxt('ruby-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-11">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> euler2b<span style="color:#006600; font-weight:bold;">&#40;</span>max,a=<span style="color:#006666;color:#800000;">1</span>,b=<span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; fib2<span style="color:#006600; font-weight:bold;">&#40;</span>max,a,b<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span>|x| x%<span style="color:#006666;color:#800000;">2</span>==<span style="color:#006666;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#123;</span>|memo,obj| memo+obj<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">puts</span> euler2b<span style="color:#006600; font-weight:bold;">&#40;</span>4e6<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Tercera soluciÃ³n:</strong></p>
<p>Esta tercera soluciÃ³n es una modificaciÃ³n directa de la segunda. En vez de almacenar los datos, se suman directamente.</p>
<div class="igBar"><span id="lruby-12"><a href="#" onclick="javascript:showPlainTxt('ruby-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-12">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> fib3<span style="color:#006600; font-weight:bold;">&#40;</span>max,a=<span style="color:#006666;color:#800000;">1</span>,b=<span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; res = <span style="color:#006666;color:#800000;">0</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; res += a <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">yield</span><span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span>b&lt;max<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; res += b <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">yield</span><span style="color:#006600; font-weight:bold;">&#40;</span>b<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; a,b=b,a+b</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; res</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> euler2c<span style="color:#006600; font-weight:bold;">&#40;</span>max,a=<span style="color:#006666;color:#800000;">1</span>,b=<span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; fib3<span style="color:#006600; font-weight:bold;">&#40;</span>max,a,b<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span>|x| x%<span style="color:#006666;color:#800000;">2</span>==<span style="color:#006666;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">puts</span> euler2c<span style="color:#006600; font-weight:bold;">&#40;</span>4e6<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Y eso es todo.</p>
<p><strong>ActualizaciÃ³n:</strong> Hay diferencias entre la pÃ¡gina de PyEuler y la del Proyecto Euler. El problema ha sido actualizado para corresponderse con esta Ãºltima.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Problema 2 on Serabe Reloaded',url: 'http://www.serabe.com/2008/03/23/problema-2/',contentID: 'post-165',suggestTags: 'euler project,Maths,Programming,programming,RbEuler,Ruby',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Problema 2" alt="article clipper Problema 2" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.serabe.com%2F2008%2F03%2F23%2Fproblema-2%2F&amp;title=Problema%202" id="wpa2a_4"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="share save 171 16 Problema 2"  title="Problema 2" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/03/23/problema-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

