in reply to Re: finding perfect numbers
in thread finding perfect numbers

Thanks, this variant even works with warnings enabled and older Perls:
use strict; use warnings; use Math::Factor::XS qw/factors/; use List::Util qw/sum/; for (2 .. 10000) { print "$_ is perfect\n" if (sum(factors($_),0) == $_ - 1); }

Replies are listed 'Best First'.
Re^3: finding perfect numbers
by CountZero (Bishop) on Aug 06, 2010 at 10:56 UTC
    Well done!

    And that made me think of the following small change:

    print "$_ is perfect\n" if (sum(factors($_),1) == $_);
    Thanks for putting me on that track!

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James