Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: General style advice requested

by choroba (Cardinal)
on Oct 29, 2010 at 14:47 UTC ( [id://868319]=note: print w/replies, xml ) Need Help??


in reply to Re: General style advice requested
in thread General style advice requested

Thanks for the link :-) I also tried the first assignment yesterday, but with a small speed-up included. See for comparison:
#!/usr/bin/perl use warnings; use strict; my %cache = (1 => 0); sub _three_n_plus_1 { no warnings qw/recursion/; my ($n,$count) = @_; $count ||= 1; return $count + $cache{$n} if exists $cache{$n}; if($n % 2){ $cache{$n} = _three_n_plus_1(3*$n+1, $count+1) - $count; return $cache{$n} + $count; }else{ $cache{$n} = _three_n_plus_1($n/2, $count+1) - $count; return $cache{$n} + $count; } } sub three_n_plus_1 { my ($i,$j) = @_; my $max = 0; for my $x ($i<$j ? $i..$j : $j..$i){ my $t = _three_n_plus_1($x); $max = $t if $t > $max; } print "$i $j $max\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://868319]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2026-03-06 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.