citizen428.blog()

Try to learn something about everything

I'm in Your Pi, Crunching Your Numbers ;-)

From Ruby Quiz #202:

And sometimes the fastest code is the code you don’t write. Michael Kohl’s solution:

1
2
3
4
5

1
2
3
4
5
<span class='line'><span class="nb">require</span> <span class="s1">&#39;rubygems&#39;</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">&#39;hpricot&#39;</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">&#39;open-uri&#39;</span>
</span><span class='line'><span class="n">doc</span> <span class="o">=</span> <span class="no">Hpricot</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="s1">&#39;http://www.eveandersson.com/pi/digits/100000&#39;</span><span class="p">))</span>
</span><span class='line'><span class="nb">puts</span> <span class="p">(</span><span class="n">doc</span><span class="o">/</span><span class="s1">&#39;pre&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">inner_html</span>
</span>

It finishes in less than one second for the entire 100,000 digits!

And no, this wasn’t a serious submission… :-)

Comments

Copyright © 2016 - Michael Kohl - Powered by Octopress