Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Created October 7, 2021 12:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogbert17/7099a67e3991c2920a142a3b6ac0a08f to your computer and use it in GitHub Desktop.
Save dogbert17/7099a67e3991c2920a142a3b6ac0a08f to your computer and use it in GitHub Desktop.
Runs faster with expr-jit turned off
# 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