Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Dominus's scratchpad

by Dominus (Parson)
on Jun 01, 2004 at 22:19 UTC ( [id://358683]=scratchpad: print w/replies, xml ) Need Help??

use strict; use warnings; use Memoize; $| = 1; memoize('f_fenLisesi'); my $LARGE_N = shift || 300_000; for (\&f_fenLisesi, \&f_mjd, \&f_swampyankee) { print "7! = ", $_->(7), "\n"; } time_this( \&f_fenLisesi, 'fenLisesi' ); time_this( \&f_mjd, 'mjd' ); time_this( \&f_swampyankee, 'swampyankee'); exit( 0 ); #--------------------------------------------------+ sub time_this { my ($cref, $test_name) = @_; my $start = time(); print "testing $test_name: "; for (1 .. $LARGE_N) { $cref->( $_ ); } printf "%d second(s)\n", time() - $start; } #--------------------------------------------------+ sub f_swampyankee { my ($n) = @_; my $sum = 0; for my $i (1 .. $n) { $sum += $i; } $sum; } ##--------------------------------------------------+ sub f_fenLisesi { my ($n) = @_; return 1 if $n == 1; $n + f_fenLisesi( $n - 1 ); } ##--------------------------------------------------+ my @fact; BEGIN {@fact = (0)} sub f_mjd { my ($n) = @_; while ($#fact < $n) { push @fact, @fact + $fact[-1]; } return $fact[$n]; }
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found