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"; }

In reply to Re^2: General style advice requested by choroba
in thread General style advice requested by iangibson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.