<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Torturing Ruby (and laughing at your own code)</title>
	<atom:link href="http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/</link>
	<description>Andy Lo-A-Foe's weblog</description>
	<lastBuildDate>Mon, 15 Feb 2010 16:03:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: p3t0r</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-290</link>
		<dc:creator>p3t0r</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-290</guid>
		<description>What about:

number.to_s.scan(/\d{1,4}/)</description>
		<content:encoded><![CDATA[<p>What about:</p>
<p>number.to_s.scan(/\d{1,4}/)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p3tor</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-291</link>
		<dc:creator>p3tor</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-291</guid>
		<description>I just had to pass my solution to flog:
&lt;pre&gt;
Total score = 2.89233901885654

main#splice_number: (2.9)
     1.3: to_s
     1.1: scan
     1.1: assignment
     0.3: lit_fixnum
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I just had to pass my solution to flog:<br />
&lt;pre&gt;<br />
Total score = 2.89233901885654</p>
<p>main#splice_number: (2.9)<br />
     1.3: to_s<br />
     1.1: scan<br />
     1.1: assignment<br />
     0.3: lit_fixnum<br />
&lt;/pre&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p3t0r</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-292</link>
		<dc:creator>p3t0r</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-292</guid>
		<description>I simplified a bit to much, didn&#039;t put the &#039;part_size&#039; into the equation, this should do the same as yours:

&lt;pre&gt;
def splice_number(number, part_size = 4)
  p = Regexp.new(&quot;\\d{1,#{part_size}}&quot;)
  number.to_s.scan(p)
end
&lt;/pre&gt;

And results in a 4.4

&lt;pre&gt;
Total score = 4.36928197762516

main#splice_number: (4.4)
     2.2: assignment
     1.3: to_s
     1.1: new
     1.1: scan
     0.3: lit_fixnum
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I simplified a bit to much, didn&#8217;t put the &#8216;part_size&#8217; into the equation, this should do the same as yours:</p>
<p>&lt;pre&gt;<br />
def splice_number(number, part_size = 4)<br />
  p = Regexp.new(&quot;\\d{1,#{part_size}}&quot;)<br />
  number.to_s.scan(p)<br />
end<br />
&lt;/pre&gt;</p>
<p>And results in a 4.4</p>
<p>&lt;pre&gt;<br />
Total score = 4.36928197762516</p>
<p>main#splice_number: (4.4)<br />
     2.2: assignment<br />
     1.3: to_s<br />
     1.1: new<br />
     1.1: scan<br />
     0.3: lit_fixnum<br />
&lt;/pre&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andy</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-293</link>
		<dc:creator>andy</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-293</guid>
		<description>Excellent!! :-)</description>
		<content:encoded><![CDATA[<p>Excellent!! <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andy</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-294</link>
		<dc:creator>andy</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-294</guid>
		<description>I completely miss the presence of the scan method call, and in Ruby fashion is supports regex!

-andy</description>
		<content:encoded><![CDATA[<p>I completely miss the presence of the scan method call, and in Ruby fashion is supports regex!</p>
<p>-andy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p3t0r</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-295</link>
		<dc:creator>p3t0r</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-295</guid>
		<description>You miss the presence of the scan call? The above really works in ruby, I&#039;ve tested it!</description>
		<content:encoded><![CDATA[<p>You miss the presence of the scan call? The above really works in ruby, I&#8217;ve tested it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andy</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-296</link>
		<dc:creator>andy</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-296</guid>
		<description>What I meant, *I* didn&#039;t know about the scan call in the Ruby String class :-) .. very handy indeed, thanks!!&lt;br/&gt;
&lt;br/&gt;
-andy</description>
		<content:encoded><![CDATA[<p>What I meant, *I* didn&#8217;t know about the scan call in the Ruby String class <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  .. very handy indeed, thanks!!&lt;br/&gt;<br />
&lt;br/&gt;<br />
-andy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Hodel</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-297</link>
		<dc:creator>Eric Hodel</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-297</guid>
		<description>&lt;pre&gt;$ flog
def splice_number(number, part_size = 4)
  number.to_s.scan(/\d{1,#{part_size}}/)
end
Total score = 3.775

none#splice_number: (3.8)
     1.3: to_s
     1.1: scan
     1.1: assignment
     0.3: lit_fixnum&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>&lt;pre&gt;$ flog<br />
def splice_number(number, part_size = 4)<br />
  number.to_s.scan(/\d{1,#{part_size}}/)<br />
end<br />
Total score = 3.775</p>
<p>none#splice_number: (3.8)<br />
     1.3: to_s<br />
     1.1: scan<br />
     1.1: assignment<br />
     0.3: lit_fixnum&lt;/pre&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Davis</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-298</link>
		<dc:creator>Ryan Davis</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-298</guid>
		<description>Great article... unpack is indeed the way to go.&lt;br/&gt;
That a* + delete is more expensive than just seeing if it is needed in the first place:&lt;br/&gt;
&lt;br/&gt;
&lt;pre&gt;
def splice_number6(n, p = 4)
  # flog = 10.92, time = 5.17
  n = n.to_s
  s = n.size
  c = s / p
  fmt = &quot;a#{p}&quot; * c
  fmt &lt;&lt; &quot;a*&quot; unless s == p * c
  n.unpack(fmt)
end
&lt;/pre&gt;

Here are the flog (1.1) scores + times for the above implementations:

&lt;pre&gt;
flog = 32.26, time = 10.48
flog = 10.51, time = 06.54
flog = 10.36, time = 06.70
flog = 04.37, time = 12.32 # peter
flog = 02.89, time = 11.82 # eric
flog = 10.92, time = 05.17 # me
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Great article&#8230; unpack is indeed the way to go.&lt;br/&gt;<br />
That a* + delete is more expensive than just seeing if it is needed in the first place:&lt;br/&gt;<br />
&lt;br/&gt;<br />
&lt;pre&gt;<br />
def splice_number6(n, p = 4)<br />
  # flog = 10.92, time = 5.17<br />
  n = n.to_s<br />
  s = n.size<br />
  c = s / p<br />
  fmt = &quot;a#{p}&quot; * c<br />
  fmt &amp;lt;&amp;lt; &quot;a*&quot; unless s == p * c<br />
  n.unpack(fmt)<br />
end<br />
&lt;/pre&gt;</p>
<p>Here are the flog (1.1) scores + times for the above implementations:</p>
<p>&lt;pre&gt;<br />
flog = 32.26, time = 10.48<br />
flog = 10.51, time = 06.54<br />
flog = 10.36, time = 06.70<br />
flog = 04.37, time = 12.32 # peter<br />
flog = 02.89, time = 11.82 # eric<br />
flog = 10.92, time = 05.17 # me<br />
&lt;/pre&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p3t0r</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/comment-page-1/#comment-299</link>
		<dc:creator>p3t0r</dc:creator>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code#comment-299</guid>
		<description>@EricHodel Thanks, didn&#039;t know you could use th #{ notation inside a regexp like that!
@RyanDavis Yeah, I&#039;d expect regex to be outperformed by unpack. The regexp method is IMHO a bit more flexible.. one could easily make it have a &#039;min_part_size&#039; or work on character strings.</description>
		<content:encoded><![CDATA[<p>@EricHodel Thanks, didn&#8217;t know you could use th #{ notation inside a regexp like that!<br />
@RyanDavis Yeah, I&#8217;d expect regex to be outperformed by unpack. The regexp method is IMHO a bit more flexible.. one could easily make it have a &#8216;min_part_size&#8217; or work on character strings.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
