aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2022-06-19 11:44:43 +0000
committerMark <53903062+andemark@users.noreply.github.com>2022-06-19 11:44:43 +0000
commit665dfe6b38d7cf8240456acac231a8c5d3cbe171 (patch)
tree093684c5856707ce6f8f8ae5d1a8f1a674a30d6c
parentb31f81e8327b55cd8963314fb205bc918e432b74 (diff)
downloadperlweeklychallenge-club-665dfe6b38d7cf8240456acac231a8c5d3cbe171.tar.gz
perlweeklychallenge-club-665dfe6b38d7cf8240456acac231a8c5d3cbe171.tar.bz2
perlweeklychallenge-club-665dfe6b38d7cf8240456acac231a8c5d3cbe171.zip
Bug fix for ch-2.raku
-rw-r--r--challenge-169/mark-anderson/raku/ch-2.raku36
1 files changed, 20 insertions, 16 deletions
diff --git a/challenge-169/mark-anderson/raku/ch-2.raku b/challenge-169/mark-anderson/raku/ch-2.raku
index ea4ca0906b..d5a54c637b 100644
--- a/challenge-169/mark-anderson/raku/ch-2.raku
+++ b/challenge-169/mark-anderson/raku/ch-2.raku
@@ -1,26 +1,34 @@
#!/usr/bin/env raku
-my $n = 100_000_000;
+# This program generates 10,000 Achilles numbers in under 2 seconds.
+
+my \n = 90209312; # The 10,000th Achilles number from https://oeis.org/A052486/b052486.txt
my $powerful = set gather
-for 2..sqrt($n) -> $a
{
- for 1..* -> $b
+ for 1..sqrt(n) -> $a
{
- my $c = $a**2 * $b**3;
- last if $c > $n;
- take $c;
+ for 1..* -> $b
+ {
+ my $c = $a**2 * $b**3;
+ last if $c > n;
+ take $c;
+ }
}
}
-my $perfect = set gather
-for 2..sqrt($n) -> $a
+my $perfect = set gather
{
- for 2..* -> $b
+ take 1;
+
+ for 2..sqrt(n) -> $a
{
- my $c = $a**$b;
- last if $c > $n;
- take $c;
+ for 2..* -> $b
+ {
+ my $c = $a**$b;
+ last if $c > n;
+ take $c;
+ }
}
}
@@ -29,7 +37,3 @@ 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