diff options
| -rw-r--r-- | challenge-169/mark-anderson/raku/ch-2.raku | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/challenge-169/mark-anderson/raku/ch-2.raku b/challenge-169/mark-anderson/raku/ch-2.raku index ea4548a0f4..ea4ca0906b 100644 --- a/challenge-169/mark-anderson/raku/ch-2.raku +++ b/challenge-169/mark-anderson/raku/ch-2.raku @@ -1,29 +1,35 @@ #!/usr/bin/env raku -use Prime::Factor; -use Test; +my $n = 100_000_000; -is-deeply Achilles[^100], - (72, 108, 200, 288, 392, 432, 500, 648, 675, 800, - 864, 968, 972, 1125, 1152, 1323, 1352, 1372, 1568, 1800, - 1944, 2000, 2312, 2592, 2700, 2888, 3087, 3200, 3267, 3456, - 3528, 3872, 3888, 4000, 4232, 4500, 4563, 4608, 5000, 5292, - 5324, 5400, 5408, 5488, 6075, 6125, 6272, 6728, 6912, 7200, - 7688, 7803, 8575, 8712, 8748, 8788, 9000, 9248, 9747, 9800, - 10125, 10368, 10584, 10800, 10952, 10976, 11552, 11907, 11979, 12168, - 12348, 12500, 12800, 13068, 13448, 13500, 14112, 14283, 14792, 15125, - 15488, 15552, 16000, 16200, 16875, 16928, 17496, 17672, 18000, 18252, - 18432, 19208, 19652, 19773, 20000, 20808, 21125, 21168, 21296, 21600); - -sub Achilles -{ - sub Achilles(\n) +my $powerful = set gather +for 2..sqrt($n) -> $a +{ + for 1..* -> $b { - my \pf = prime-factors(n).List; - my \powerful = so n %% all pf.squish >>**>> 2; - my \imperfect = ([gcd] pf.Bag.values) == 1; - powerful and imperfect + my $c = $a**2 * $b**3; + last if $c > $n; + take $c; } +} - (2..*).hyper.grep(&Achilles) +my $perfect = set gather +for 2..sqrt($n) -> $a +{ + for 2..* -> $b + { + my $c = $a**$b; + last if $c > $n; + take $c; + } } + +my $achilles = $powerful (-) $perfect; +my @achilles = $achilles.keys.sort; + +say @achilles[^20]; # (72 108 200 288 392 432 500 648 675 800 864 968 972 1125 1152 1323 1352 1372 1568 1800) +say @achilles[9990..9999]; # (90025452 90048200 90100125 90101888 90117775 90124083 90124672 90140256 90155592 90209312) + +# real 1.45 +# user 1.69 +# sys 0.10 |
