Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub proper-divisors (int $number --> int)
- {
- my int $candidate = 0;
- my int $divisors = 1;
- my int $number_sqrt = $number.sqrt.Int + 1;
- for 2 .. $number_sqrt -> $candidate
- {
- $divisors = $divisors + 2 if $number %% $candidate;
- }
- $divisors + 1;
- }
- sub find-number(--> int) {
- my int $record = 0;
- my int $triangle = 21;
- for 7..Inf {
- $triangle = $triangle + $_;
- my $result = proper-divisors($triangle);
- if $result > $record {
- $record = $result;
- say $record, "-", $_;
- }
- if $result > 500 {
- return $triangle;
- }
- }
- }
- say find-number();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement