in reply to Re^2: Finding all divisors of an integer
in thread Finding all divisors of an integer

@divisors = grep { $number % $_ == 0 } 1 .. sqrt($number);
I think you are thinking of prime factorization here. You can stop there to determine primeness but not to determine all factors.

You somehow miss the second line of my optimized solution. It adds the other half of the divisors. :-)

push @divisors, map {$number == $_*$_ ? () : $number/$_} reverse @divi +sors;

For every divisor above the square root, there is a corresponding divisor below the square root. Symmetrical optimization. :-)

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.