<?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; Anti-GOTAM</title>
	<atom:link href="http://www.serabe.com/category/anti-gotam/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>Hug a developer today.</title>
		<link>http://www.serabe.com/2008/08/28/hug-a-developer-today/</link>
		<comments>http://www.serabe.com/2008/08/28/hug-a-developer-today/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 09:55:23 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Humor]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vÃ­deo]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=232</guid>
		<description><![CDATA[Hug a developer today. They are in pain. At least, I work for a Open Source project, so I have no boss... but me. Anyway, you can hug me if you want . Taken from. &#160;]]></description>
			<content:encoded><![CDATA[<p><embed src="http://blip.tv/play/gYwjwZJqjdEh" type="application/x-shockwave-flash" width="640" height="390" allowscriptaccess="always" allowfullscreen="true"></embed> </p>
<p>Hug a developer today. They are in pain. At least, I work for a Open Source project, so I have no boss... but me.</p>
<p>Anyway, you can hug me if you want <img src='http://www.serabe.com/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Hug a developer today." class='wp-smiley' title="Hug a developer today." /> .</p>
<p><a href="http://develop-one.net/blog/2008/08/27/HugADeveloper.aspx" >Taken from</a>.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Hug a developer today. on Serabe Reloaded',url: 'http://www.serabe.com/2008/08/28/hug-a-developer-today/',contentID: 'post-232',suggestTags: 'Humor,programming,vÃ­deo',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Hug a developer today." alt="article clipper Hug a developer today." />
				</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%2F08%2F28%2Fhug-a-developer-today%2F&amp;title=Hug%20a%20developer%20today." 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 Hug a developer today."  title="Hug a developer today." /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/08/28/hug-a-developer-today/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diferencias</title>
		<link>http://www.serabe.com/2008/05/12/diferencias/</link>
		<comments>http://www.serabe.com/2008/05/12/diferencias/#comments</comments>
		<pubDate>Mon, 12 May 2008 14:39:44 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Humor]]></category>
		<category><![CDATA[carteles]]></category>
		<category><![CDATA[diferencias]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=196</guid>
		<description><![CDATA[&#160;]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.serabe.com/wp-content/uploads/2008/05/1210506134_foto_38897.jpg" ><img src="http://www.serabe.com/wp-content/uploads/2008/05/1210506134_foto_38897-223x300.jpg" alt="1210506134 foto 38897 223x300 Diferencias" title="Diferencias" width="223" height="300" class="alignnone size-medium wp-image-197" /></a></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Diferencias on Serabe Reloaded',url: 'http://www.serabe.com/2008/05/12/diferencias/',contentID: 'post-196',suggestTags: 'carteles,diferencias,Humor',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Diferencias" alt="article clipper Diferencias" />
				</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%2F05%2F12%2Fdiferencias%2F&amp;title=Diferencias" id="wpa2a_6"><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 Diferencias"  title="Diferencias" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/05/12/diferencias/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tweets del 01-04-2008</title>
		<link>http://www.serabe.com/2008/04/01/tweets-del-01-04-2008/</link>
		<comments>http://www.serabe.com/2008/04/01/tweets-del-01-04-2008/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 22:59:59 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[canciones al revés]]></category>
		<category><![CDATA[expresiones regulares]]></category>

		<guid isPermaLink="false">http://www.serabe.com/2008/04/01/tweets-del-01-04-2008/</guid>
		<description><![CDATA[Free Graph Paper Creator http://www.printfreegraphpaper.com/ # Regex Mate http://regexmate.com/ # Songs Backwards Online http://www.talkbackwards.com/ # &#160;]]></description>
			<content:encoded><![CDATA[<ul>
<li>Free Graph Paper Creator <a href="http://www.printfreegraphpaper.com/"  rel="nofollow">http://www.printfreegraphpaper.com/</a> <a href="http://twitter.com/Serabe/statuses/780928557" >#</a></li>
<li>Regex Mate <a href="http://regexmate.com/"  rel="nofollow">http://regexmate.com/</a> <a href="http://twitter.com/Serabe/statuses/780931845" >#</a></li>
<li>Songs Backwards Online <a href="http://www.talkbackwards.com/"  rel="nofollow">http://www.talkbackwards.com/</a> <a href="http://twitter.com/Serabe/statuses/780934619" >#</a></li>
</ul>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Tweets del 01-04-2008 on Serabe Reloaded',url: 'http://www.serabe.com/2008/04/01/tweets-del-01-04-2008/',contentID: 'post-173',suggestTags: 'canciones al revés,expresiones regulares',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Tweets del 01 04 2008" alt="article clipper Tweets del 01 04 2008" />
				</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%2F04%2F01%2Ftweets-del-01-04-2008%2F&amp;title=Tweets%20del%2001-04-2008" id="wpa2a_8"><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 Tweets del 01 04 2008"  title="Tweets del 01 04 2008" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/04/01/tweets-del-01-04-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tweets del 29-03-2008</title>
		<link>http://www.serabe.com/2008/03/29/tweets-del-29-03-2008/</link>
		<comments>http://www.serabe.com/2008/03/29/tweets-del-29-03-2008/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 22:59:59 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Otros]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[perspectiva]]></category>
		<category><![CDATA[shell programming]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.serabe.com/2008/03/29/tweets-del-29-03-2008/</guid>
		<description><![CDATA[Shell-Fu http://www.shell-fu.org/ # Cents of Perspective http://tinyurl.com/3xdara # &#160;]]></description>
			<content:encoded><![CDATA[<ul>
<li>Shell-Fu <a href="http://www.shell-fu.org/"  rel="nofollow">http://www.shell-fu.org/</a> <a href="http://twitter.com/Serabe/statuses/779194222" >#</a></li>
<li>Cents of Perspective <a href="http://tinyurl.com/3xdara"  rel="nofollow">http://tinyurl.com/3xdara</a> <a href="http://twitter.com/Serabe/statuses/779370742" >#</a></li>
</ul>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Tweets del 29-03-2008 on Serabe Reloaded',url: 'http://www.serabe.com/2008/03/29/tweets-del-29-03-2008/',contentID: 'post-172',suggestTags: 'perspectiva,shell programming,snippets',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Tweets del 29 03 2008" alt="article clipper Tweets del 29 03 2008" />
				</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%2F29%2Ftweets-del-29-03-2008%2F&amp;title=Tweets%20del%2029-03-2008" id="wpa2a_10"><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 Tweets del 29 03 2008"  title="Tweets del 29 03 2008" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/03/29/tweets-del-29-03-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tweets del 26-03-2008</title>
		<link>http://www.serabe.com/2008/03/26/tweets-del-26-03-2008/</link>
		<comments>http://www.serabe.com/2008/03/26/tweets-del-26-03-2008/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 22:59:59 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Physics]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[décima dimensión]]></category>
		<category><![CDATA[dimensiones]]></category>
		<category><![CDATA[fax]]></category>

		<guid isPermaLink="false">http://www.serabe.com/2008/03/26/tweets-del-26-03-2008/</guid>
		<description><![CDATA[cdfax http://0xcc.net/cdfax/index.html.en # Imagining the Tenth Dimension / Imaginando la dÃ©cima dimensiÃ³n http://tinyurl.com/2kkd7y # &#160;]]></description>
			<content:encoded><![CDATA[<ul>
<li>cdfax <a href="http://0xcc.net/cdfax/index.html.en"  rel="nofollow">http://0xcc.net/cdfax/index.html.en</a> <a href="http://twitter.com/Serabe/statuses/777646903" >#</a></li>
<li>Imagining the Tenth Dimension / Imaginando la dÃ©cima dimensiÃ³n <a href="http://tinyurl.com/2kkd7y"  rel="nofollow">http://tinyurl.com/2kkd7y</a> <a href="http://twitter.com/Serabe/statuses/777664747" >#</a></li>
</ul>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Tweets del 26-03-2008 on Serabe Reloaded',url: 'http://www.serabe.com/2008/03/26/tweets-del-26-03-2008/',contentID: 'post-169',suggestTags: 'décima dimensión,dimensiones,fax,Physics',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Tweets del 26 03 2008" alt="article clipper Tweets del 26 03 2008" />
				</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%2F26%2Ftweets-del-26-03-2008%2F&amp;title=Tweets%20del%2026-03-2008" id="wpa2a_12"><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 Tweets del 26 03 2008"  title="Tweets del 26 03 2008" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/03/26/tweets-del-26-03-2008/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_14"><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>
		<item>
		<title>Tweets del 19-03-2008</title>
		<link>http://www.serabe.com/2008/03/19/tweets-del-19-03-2008/</link>
		<comments>http://www.serabe.com/2008/03/19/tweets-del-19-03-2008/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 22:59:59 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Maths]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.serabe.com/2008/03/19/tweets-del-19-03-2008/</guid>
		<description><![CDATA[Â¿Un objeto imposible? http://tinyurl.com/2nnd7b # &#160;]]></description>
			<content:encoded><![CDATA[<ul>
<li>Â¿Un objeto imposible? <a href="http://tinyurl.com/2nnd7b"  rel="nofollow">http://tinyurl.com/2nnd7b</a> <a href="http://twitter.com/Serabe/statuses/773978883" >#</a></li>
</ul>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Tweets del 19-03-2008 on Serabe Reloaded',url: 'http://www.serabe.com/2008/03/19/tweets-del-19-03-2008/',contentID: 'post-163',suggestTags: 'Maths',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Tweets del 19 03 2008" alt="article clipper Tweets del 19 03 2008" />
				</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%2F19%2Ftweets-del-19-03-2008%2F&amp;title=Tweets%20del%2019-03-2008" id="wpa2a_16"><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 Tweets del 19 03 2008"  title="Tweets del 19 03 2008" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/03/19/tweets-del-19-03-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tweets del 16-03-2008</title>
		<link>http://www.serabe.com/2008/03/16/tweets-del-16-03-2008/</link>
		<comments>http://www.serabe.com/2008/03/16/tweets-del-16-03-2008/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 22:59:59 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Anti-GOTAM]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[tutoriales]]></category>

		<guid isPermaLink="false">http://www.serabe.com/2008/03/16/tweets-del-16-03-2008/</guid>
		<description><![CDATA[Aprende ProgramaciÃ³n Online Gratis http://tinyurl.com/35huo8 # La colecciÃ³n de los &#34;Hola, Mundo&#34; http://tinyurl.com/zots7 # &#160;]]></description>
			<content:encoded><![CDATA[<ul>
<li>Aprende ProgramaciÃ³n Online Gratis <a href="http://tinyurl.com/35huo8"  rel="nofollow">http://tinyurl.com/35huo8</a> <a href="http://twitter.com/Serabe/statuses/772337249" >#</a></li>
<li>La colecciÃ³n de los &quot;Hola, Mundo&quot; <a href="http://tinyurl.com/zots7"  rel="nofollow">http://tinyurl.com/zots7</a> <a href="http://twitter.com/Serabe/statuses/772358703" >#</a></li>
</ul>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Tweets del 16-03-2008 on Serabe Reloaded',url: 'http://www.serabe.com/2008/03/16/tweets-del-16-03-2008/',contentID: 'post-160',suggestTags: 'hello world,Programming,tutoriales',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Tweets del 16 03 2008" alt="article clipper Tweets del 16 03 2008" />
				</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%2F16%2Ftweets-del-16-03-2008%2F&amp;title=Tweets%20del%2016-03-2008" id="wpa2a_18"><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 Tweets del 16 03 2008"  title="Tweets del 16 03 2008" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/03/16/tweets-del-16-03-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problema 1</title>
		<link>http://www.serabe.com/2008/02/27/problema-1/</link>
		<comments>http://www.serabe.com/2008/02/27/problema-1/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 12:20:56 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Maths]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RubyEuler]]></category>
		<category><![CDATA[RbEuler]]></category>

		<guid isPermaLink="false">http://www.serabe.com/2008/02/27/problema-1/</guid>
		<description><![CDATA[Empiezo aquÃ­ una serie de artÃ­culos de periodicidad variable que lo Ãºnico que pretende es ser algo similar (de una manera muy amplia) a PyEuler. La lista completa de problemas estÃ¡ en el Proyecto Euler y, como no podÃ­a ser de otra manera, empiezo por el primero. Enunciado: Halla la suma de todos los nÃºmeros [...]]]></description>
			<content:encoded><![CDATA[<p>Empiezo aquÃ­ una serie de artÃ­culos de periodicidad variable que lo Ãºnico que pretende es ser algo similar (de una manera muy amplia) a <a href="http://pyeuler.wikidot.com/"  title="Sitio de PyEuler">PyEuler</a>. La lista completa de problemas estÃ¡ en el <a href="http://projecteuler.net/"  title="Sitio del Proyecto Euler">Proyecto Euler</a> y, como no podÃ­a ser de otra manera, empiezo por el primero.</p>
<p><strong>Enunciado:</strong><br />
Halla la suma de todos los nÃºmeros menores que 1000 y mÃºltiplos de 3 o de 5.</p>
<p><strong>SoluciÃ³n 1:</strong></p>
<div class="igBar"><span id="lruby-18"><a href="#" onclick="javascript:showPlainTxt('ruby-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-18">
<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> euler1a<span style="color:#006600; font-weight:bold;">&#40;</span>e, numbers<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:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">1</span>..<span style="color:#9900CC;">e</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">select</span><span style="color:#006600; font-weight:bold;">&#123;</span>|x| numbers.<span style="color:#9900CC;">any</span>?<span style="color:#006600; font-weight:bold;">&#123;</span>|y| <span style="color:#006600; font-weight:bold;">&#40;</span>x%y == <span style="color:#006666;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</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,o| memo+=o<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> euler1a<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">1000</span>,<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">3</span>,<span style="color:#006666;color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
La explicaciÃ³n es simple. Tenemos un rango desde 1 hasta el lÃ­mite, filtramos los que son mÃºltiplos de algÃºn elemento del array y despuÃ©s se suman.</p>
<p><strong>SoluciÃ³n 2:</strong></p>
<div class="igBar"><span id="lruby-19"><a href="#" onclick="javascript:showPlainTxt('ruby-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-19">
<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> euler1b<span style="color:#006600; font-weight:bold;">&#40;</span>e,numbers<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:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">1</span>..<span style="color:#9900CC;">e</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span>|memo,o| <span style="color:#006600; font-weight:bold;">&#40;</span>numbers.<span style="color:#9900CC;">any</span>?<span style="color:#006600; font-weight:bold;">&#123;</span>|x| <span style="color:#006600; font-weight:bold;">&#40;</span>o%x<span style="color:#006600; font-weight:bold;">&#41;</span>==<span style="color:#006666;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? memo+o : memo <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> euler1b<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">1000</span>,<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">3</span>,<span style="color:#006666;color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Ã‰ste es similar al anterior, sÃ³lo que se suma segÃºn se recorre el rango.</p>
<p><strong>SoluciÃ³n 3:</strong><br />
Para este necesitamos antes un par de funciones. La primera, halla el mÃ¡ximo comÃºn divisor de dos nÃºmeros. Para ello, bÃ¡sicamente usa el <a rel="nofollow" href="http://es.wikipedia.org/wiki/Algoritmo_de_Euclides"  title="Wikipedia">algoritmo de Euclides</a>.</p>
<div class="igBar"><span id="lruby-20"><a href="#" onclick="javascript:showPlainTxt('ruby-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-20">
<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> mcd<span style="color:#006600; font-weight:bold;">&#40;</span>n1,n2<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;">if</span> n1 &lt;n2</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; mcd<span style="color:#006600; font-weight:bold;">&#40;</span>n2,n1<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;">elsif</span> <span style="color:#006600; font-weight:bold;">&#40;</span>n1%n2<span style="color:#006600; font-weight:bold;">&#41;</span> == <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; &nbsp; n2</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;">else</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; mcd<span style="color:#006600; font-weight:bold;">&#40;</span>n2,n1%n2<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;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Por otra parte, estÃ¡ la funciÃ³n que calcula el mÃ­nimo comÃºn mÃºltiplo. Para ello usa su relaciÃ³n con el <abbr title="MÃ¡ximo ComÃºn Divisor">m.c.d.</abbr>.</p>
<div class="igBar"><span id="lruby-21"><a href="#" onclick="javascript:showPlainTxt('ruby-21'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-21">
<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> mcm<span style="color:#006600; font-weight:bold;">&#40;</span>n1,n2<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; n1*n2/mcd<span style="color:#006600; font-weight:bold;">&#40;</span>n1,n2<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;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Con esto, ya podemos pasar a la tercera soluciÃ³n, que es diferente de las otras dos en que sÃ³lo sirve si utilizamos dos nÃºmeros como filtro.</p>
<div class="igBar"><span id="lruby-22"><a href="#" onclick="javascript:showPlainTxt('ruby-22'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-22">
<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> euler1c<span style="color:#006600; font-weight:bold;">&#40;</span>limit, n1, n2<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:#006600; font-weight:bold;">&#40;</span>n1*<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>limit/n1<span style="color:#006600; font-weight:bold;">&#41;</span>*<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>limit/n1<span style="color:#006600; font-weight:bold;">&#41;</span>+<span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>/<span style="color:#006666;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>+n2*<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>limit/n2<span style="color:#006600; font-weight:bold;">&#41;</span>*<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>limit/n2<span style="color:#006600; font-weight:bold;">&#41;</span>+<span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>/<span style="color:#006666;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>-mcm<span style="color:#006600; font-weight:bold;">&#40;</span>n1,n2<span style="color:#006600; font-weight:bold;">&#41;</span>*<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>limit/mcm<span style="color:#006600; font-weight:bold;">&#40;</span>n1,n2<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>*<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>limit/mcm<span style="color:#006600; font-weight:bold;">&#40;</span>n1,n2<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>+<span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>/<span style="color:#006666;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</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;"><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> euler1c<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">1000</span>,<span style="color:#006666;color:#800000;">3</span>,<span style="color:#006666;color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>La explicaciÃ³n es un poco mÃ¡s complicada, pues implica teorÃ­a bÃ¡sica de conjuntos y la conocida fÃ³rmula de la suma de 1 a n.</p>
<p>Ahora es vuestro turno. Â¿CÃ³mo se os ocurre hacerlo?</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Problema 1 on Serabe Reloaded',url: 'http://www.serabe.com/2008/02/27/problema-1/',contentID: 'post-148',suggestTags: 'Maths,RbEuler,Ruby',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Problema 1" alt="article clipper Problema 1" />
				</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%2F02%2F27%2Fproblema-1%2F&amp;title=Problema%201" id="wpa2a_20"><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 1"  title="Problema 1" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2008/02/27/problema-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

