Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Created September 23, 2021 18:04
Show Gist options
  • Save dogbert17/162bcbb76f61a406ee1a245d36fca18f to your computer and use it in GitHub Desktop.
Save dogbert17/162bcbb76f61a406ee1a245d36fca18f to your computer and use it in GitHub Desktop.
JIT error
# What is the largest prime factor of the number 600851475143 ?
use v6;
my $num = 600_851_475_143;
my $val = $num;
my @factors = ();
while ([*] @factors) != $num {
push @factors, (2...*).first(-> $x { $val %% $x && $x.is-prime });
$val = $val div @factors[*-1];
}
say @factors.max; # remove max to see all prime factors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment