<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Igor Irianto on Medium]]></title>
        <description><![CDATA[Stories by Igor Irianto on Medium]]></description>
        <link>https://medium.com/@stupendous_igg?source=rss-5d0eaa2427d6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oc_Cw6CT-npSbgKzftsUSQ.png</url>
            <title>Stories by Igor Irianto on Medium</title>
            <link>https://medium.com/@stupendous_igg?source=rss-5d0eaa2427d6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 03:02:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stupendous_igg/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[ProjectEuler] Brute force just won’t do]]></title>
            <link>https://medium.com/@stupendous_igg/projecteuler-brute-force-just-wont-do-86d41ee63337?source=rss-5d0eaa2427d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/86d41ee63337</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[project-euler]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Igor Irianto]]></dc:creator>
            <pubDate>Sun, 10 Jul 2016 05:42:44 GMT</pubDate>
            <atom:updated>2016-07-10T05:42:44.577Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*Cr7mNr1VdYhggIJirPEE3A.jpeg" /></figure><p>Sometimes simply getting the code to work won’t do it.</p><blockquote>2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?</blockquote><blockquote>— Project Euler Problem 5</blockquote><p>Initially, I came up with</p><pre>arr = (2..20).to_a</pre><pre>counter = 10</pre><pre>arr_modulo = []*10</pre><pre>while arr_modulo != [0]*10</pre><pre>    counter = counter + 1</pre><pre>    arr_modulo = arr.map {|n| counter % n}</pre><pre>end</pre><pre>puts counter</pre><p>This code works by manually checking whether each number starting from <em>counter</em> is divisible with everything inside array <em>arr. </em>It works fine — as long as the solution is relatively small. If <em>arr </em>was <em>(2..10)</em>, then it calculates within a few seconds. If <em>arr </em>was <em>(2..20) </em>however, my macbook air could not handle it. The solution was in hundreds of millions, about ten-thousand times the solution as if <em>arr </em>was <em>(1..10).</em></p><p>I learned that there will come a time when simply getting a working code does not do it. It’s like buying a vehicle that gets to point A to point B, but can’t go more than 35 mph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*v3SzpOiq2fr7QzVIHoa-pw.jpeg" /><figcaption>initial code (left)</figcaption></figure><p>A faster solution is required. After searching and thinking and mostly googling, I found another solution — solution so simple it is almost cheating.</p><pre>(1..20).inject(:lcm)</pre><p>It took ruby less time to compute the code above than my initial code with <em>arr </em>of <em>(1..10). </em>The code above utilized Ruby’s <a href="http://ruby-doc.org/core-2.2.0/Integer.html#method-i-lcm">least common multiple (lcm) built-in method</a> to automatically find common multiple (always positive) of given argument, combined with <a href="http://ruby-doc.org/core-2.3.1/Enumerable.html#method-i-inject">inject method</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*IQwuZRioJ83--lME9XiAnw.jpeg" /><figcaption>anti-moral-of-the-story</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86d41ee63337" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sum of Even Fibonacci Sequence]]></title>
            <link>https://medium.com/@stupendous_igg/sum-of-even-fibonacci-sequence-629dd9295c1e?source=rss-5d0eaa2427d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/629dd9295c1e</guid>
            <category><![CDATA[project-euler]]></category>
            <category><![CDATA[fibonacci]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Igor Irianto]]></dc:creator>
            <pubDate>Wed, 06 Jul 2016 03:21:40 GMT</pubDate>
            <atom:updated>2016-07-06T03:21:40.507Z</atom:updated>
            <content:encoded><![CDATA[<p>Sum of Even Fibonacci Sequence</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*lDyw3aVY5hePEQM5qtxkUA.png" /></figure><blockquote>By starting Fibonacci with 1 and 2, the first 10 terms will be:</blockquote><blockquote>1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …</blockquote><blockquote>By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.</blockquote><p>Excellent problem. My second take at Euler’s Project. Although it is the second easiest (possibly) problem in the website, my bragging right that I solved this problem in less than 10 minutes remains.</p><pre>def fib(max)<br> n1, n2, n = 1, 2, 0<br> arr = [n1, n2]<br> while n &lt; max<br>  n = n1 + n2<br>  n1, n2 = n2, n <br>  arr &lt;&lt; n <br> end<br> arr_sum = arr[0..-2].reject {|e| e % 2 != 0}.reduce(:+)<br>end</pre><pre>fib(4000000)</pre><p>Without looking at wikipedia, Fibonacci number is an accumulation of numbers consisted of the sum of the previous two numbers. If a Fibonacci sequence starts with 0 and 1, then the sequence goes 0, 1, (0+1), (1+(0+1)),((0+1)+(1+(0+1))), and so on. They seem to appear <a href="http://jwilson.coe.uga.edu/emat6680/parveen/fib_nature.htm">everywhere</a>, from <a href="http://io9.gizmodo.com/5985588/15-uncanny-examples-of-the-golden-ratio-in-nature">hurricanes to galaxies to pineapples.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*BS-eEaN7f3X6bJ2_wAmhNw.jpeg" /></figure><p>What other Fibonacci patterns do you recognize are around you?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=629dd9295c1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ProjEuler 1]]></title>
            <link>https://medium.com/@stupendous_igg/projeuler-7f50fa3a165a?source=rss-5d0eaa2427d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f50fa3a165a</guid>
            <category><![CDATA[project-euler]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Igor Irianto]]></dc:creator>
            <pubDate>Fri, 01 Jul 2016 21:20:14 GMT</pubDate>
            <atom:updated>2017-12-02T20:32:06.810Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*iC8ETHZEcIn_vx9V-7MGzA.png" /></figure><p>Via Ruby, there are <em>(at least in my humble head) </em>two ways of solving it:</p><p><strong>First</strong>, make an array of multiples of threes and fives, from one to nine hundred ninety-nine. Sum them up and subtract them with the the sum of array of multiples of fifteens from one to nine hundred and ninety-nine (least common divisor).</p><pre>def sum<br>  three = (1..999).to_a.reject {|n| n % 3 != 0}.reduce(:+)<br>  five = (1..999).to_a.reject {|n| n % 5 != 0}.reduce(:+)<br>  fifteen = (1..999).to_a.reject{|n| n % 15 != 0}.reduce(:+)<br>  return three + five — fifteen<br>end</pre><p><strong>Second</strong>, very similar to first code, except instead of doing adding the array up, the arrays are combined and duplicate elements are removed before being summed up.</p><pre>def sum2<br>  three = (1..999).to_a.reject {|n| n % 3 != 0}<br>  five = (1..999).to_a.reject {|n| n % 5 != 0}<br>  total = (three | five).reduce(:+)<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*L8pE17G5xfzBYMOSlCxwCw.jpeg" /></figure><blockquote>You are the 575039th person to have solved this problem.</blockquote><p>— clearly, I am an elite among the elites</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f50fa3a165a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>