Created
October 7, 2021 12:57
-
-
Save dogbert17/7099a67e3991c2920a142a3b6ac0a08f to your computer and use it in GitHub Desktop.
Runs faster with expr-jit turned off
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What is the value of the first triangle number to have over five hundred divisors? | |
use v6; | |
my $numFactors = 500; | |
my $sum = 0; | |
for (1...*) -> $term { | |
$sum += $term; | |
my $factors = (1..floor(sqrt($sum))).grep( -> $x { $sum % $x == 0} ).elems * 2; | |
$factors-- if floor(sqrt($sum)) == sqrt($sum); | |
if $factors > $numFactors { | |
say "$sum"; | |
last; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment