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">'rubygems'</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">'hpricot'</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">'open-uri'</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">'http://www.eveandersson.com/pi/digits/100000'</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">'pre'</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… :-)
|