<?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: Factorial Challenge: Python, Perl, Ruby, and C</title> <atom:link href="http://adammonsen.com/post/173/feed" rel="self" type="application/rss+xml" /><link>http://adammonsen.com/post/173?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=factorial_challenge_python_perl_ruby_and</link> <description></description> <lastBuildDate>Sat, 31 Mar 2012 19:34:03 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: Miki</title><link>http://adammonsen.com/post/173/comment-page-1#comment-11921</link> <dc:creator>Miki</dc:creator> <pubDate>Mon, 23 Mar 2009 21:53:20 +0000</pubDate> <guid isPermaLink="false">#comment-11921</guid> <description>You can get C speed in Python using &quot;gmpy&quot; module.import gmpy fact = gmpy.fac</description> <content:encoded><![CDATA[<p>You can get C speed in Python using &#8220;gmpy&#8221; module.</p><p>import gmpy<br /> fact = gmpy.fac</p> ]]></content:encoded> </item> <item><title>By: Help</title><link>http://adammonsen.com/post/173/comment-page-1#comment-11868</link> <dc:creator>Help</dc:creator> <pubDate>Mon, 10 Nov 2008 18:32:12 +0000</pubDate> <guid isPermaLink="false">#comment-11868</guid> <description>Hi, I&#039;ve been desperately searching how to (in ruby) use the factorial in ruby, and as my friend only introduced me to ruby yesterday I was hoping you could explain to me, in dumbed down terms, how to use it. If not, could you tell me where to go to ask? thanks Andrew</description> <content:encoded><![CDATA[<p>Hi, I&#8217;ve been desperately searching how to (in ruby) use the factorial in ruby, and as my friend only introduced me to ruby yesterday I was hoping you could explain to me, in dumbed down terms, how to use it. If not, could you tell me where to go to ask?<br /> thanks<br /> Andrew</p> ]]></content:encoded> </item> <item><title>By: acc</title><link>http://adammonsen.com/post/173/comment-page-1#comment-3801</link> <dc:creator>acc</dc:creator> <pubDate>Tue, 23 Jan 2007 17:33:48 +0000</pubDate> <guid isPermaLink="false">#comment-3801</guid> <description>Recursive version, equivalent to Ruby, is also fast, once you install the already mentioned package.&lt;blockquote&gt;&lt;pre&gt; #!/usr/bin/perl -w use strict;use Math::BigInt lib =&gt; &#039;GMP&#039;;use bignum;sub fact { my $n = $_[0]; ( $n == 0 ) ? 1 : $n * fact( $n - 1 ); }print fact( $ARGV[0] ), &quot;\n&quot; &lt;/pre&gt;&lt;/blockquote&gt;</description> <content:encoded><![CDATA[<p>Recursive version, equivalent to Ruby, is also fast, once you install the already mentioned package.</p><blockquote><pre>
#!/usr/bin/perl -w
use strict;

use Math::BigInt lib =&gt; 'GMP';

use bignum;

sub fact
{
    my $n = $_[0];
    ( $n == 0 )
    ? 1
    : $n * fact( $n - 1 );
}

print fact( $ARGV[0] ), "\n"
</pre></blockquote> ]]></content:encoded> </item> <item><title>By: acc</title><link>http://adammonsen.com/post/173/comment-page-1#comment-3800</link> <dc:creator>acc</dc:creator> <pubDate>Tue, 23 Jan 2007 17:24:00 +0000</pubDate> <guid isPermaLink="false">#comment-3800</guid> <description>Your Perl run was slow only because you didn&#039;t actually use GMP library there: Perl &quot;gracefully&quot; fails to Perl-written implementation, when GMP is not installed. You should start your PPM (Perl Package Manager) and install Math::BigInt::GMP package. Then, Perl would be just as fast as C, for your starting example.</description> <content:encoded><![CDATA[<p>Your Perl run was slow only because you didn&#8217;t actually use GMP library there: Perl &#8220;gracefully&#8221; fails to Perl-written implementation, when GMP is not installed. You should start your PPM (Perl Package Manager) and install Math::BigInt::GMP package. Then, Perl would be just as fast as C, for your starting example.</p> ]]></content:encoded> </item> <item><title>By: Brian</title><link>http://adammonsen.com/post/173/comment-page-1#comment-2395</link> <dc:creator>Brian</dc:creator> <pubDate>Sun, 17 Dec 2006 02:18:03 +0000</pubDate> <guid isPermaLink="false">#comment-2395</guid> <description>Here&#039;s a version that&#039;s a bit simpler and isn&#039;t recursive: &lt;blockquote&gt;&lt;pre&gt;class Fixnum def factorial (2..self).inject(1) { &#124;product, i&#124; product*i } end end&lt;/pre&gt;&lt;/blockquote&gt;It&#039;s a bit easier to use to because you can just call it this way: p 6.factorial</description> <content:encoded><![CDATA[<p>Here&#8217;s a version that&#8217;s a bit simpler and isn&#8217;t recursive:</p><blockquote><pre>class Fixnum
    def factorial
        (2..self).inject(1) { |product, i| product*i }
    end
end</pre></blockquote><p>It&#8217;s a bit easier to use to because you can just call it this way:<br /> p 6.factorial</p> ]]></content:encoded> </item> <item><title>By: muyufan</title><link>http://adammonsen.com/post/173/comment-page-1#comment-987</link> <dc:creator>muyufan</dc:creator> <pubDate>Sun, 01 Oct 2006 09:20:43 +0000</pubDate> <guid isPermaLink="false">#comment-987</guid> <description>I just exec the factorial.py file&lt;blockquote&gt;&lt;pre&gt;import time start=time.clock() def f(n):return reduce(lambda x,y:x*y,range(1,n+1)) f(n) print &quot;the time is :&quot;,time.clock()-start&lt;/pre&gt;&lt;/blockquote&gt;in my 1.6G AMD(Duron) the result is: 40!: 0.0004 (s) 10000!: 0.22 (s) 100000!: 202 (s)</description> <content:encoded><![CDATA[<p>I just exec the factorial.py file</p><blockquote><pre>import time
start=time.clock()
def f(n):return reduce(lambda x,y:x*y,range(1,n+1))
f(n)
print "the time is :",time.clock()-start</pre></blockquote><p>in my 1.6G AMD(Duron) the result is:<br /> 40!: 0.0004 (s)<br /> 10000!: 0.22 (s)<br /> 100000!: 202 (s)</p> ]]></content:encoded> </item> <item><title>By: pjh</title><link>http://adammonsen.com/post/173/comment-page-1#comment-170</link> <dc:creator>pjh</dc:creator> <pubDate>Tue, 27 Sep 2005 00:01:38 +0000</pubDate> <guid isPermaLink="false">#comment-170</guid> <description>&lt;p&gt;just for fun, the original ruby function can be replaced with:&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt; def fact(n) n == 0 ? 1 : n * fact(n-1) end &lt;/pre&gt;&lt;/blockquote&gt;</description> <content:encoded><![CDATA[<p>just for fun, the original ruby function can be replaced with:</p><blockquote><pre>
def fact(n)
  n == 0 ? 1 : n * fact(n-1)
end
</pre></blockquote> ]]></content:encoded> </item> <item><title>By: Patrick</title><link>http://adammonsen.com/post/173/comment-page-1#comment-169</link> <dc:creator>Patrick</dc:creator> <pubDate>Mon, 22 Aug 2005 00:49:00 +0000</pubDate> <guid isPermaLink="false">#comment-169</guid> <description>Adam (whose weblog requires I log in to leave comments directly) notices that python and ruby&#039;s performance seem great while C is (naturally) very fast. Perl is in the mix, too, and he kindly doesn&#039;t tear it apart though based on the numbers he would seem justified in doing so. I wondered if perl was realy that slow so I decided to take a look...</description> <content:encoded><![CDATA[<p>Adam (whose weblog requires I log in to leave comments directly) notices that python and ruby&#8217;s performance seem great while C is (naturally) very fast. Perl is in the mix, too, and he kindly doesn&#8217;t tear it apart though based on the numbers he would seem justified in doing so. I wondered if perl was realy that slow so I decided to take a look&#8230;</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: adammonsen.com @ 2012-05-17 10:26:13 -->
