diff options
| -rw-r--r-- | challenge-133/james-raspass/raku/ch-1.raku | 9 | ||||
| -rw-r--r-- | challenge-133/james-raspass/raku/ch-2.raku | 16 |
2 files changed, 25 insertions, 0 deletions
diff --git a/challenge-133/james-raspass/raku/ch-1.raku b/challenge-133/james-raspass/raku/ch-1.raku new file mode 100644 index 0000000000..769771a924 --- /dev/null +++ b/challenge-133/james-raspass/raku/ch-1.raku @@ -0,0 +1,9 @@ +sub MAIN(UInt $n) { say isqrt $n } + +multi sub isqrt(UInt:D $n where 0 | 1) { $n } +multi sub isqrt(UInt:D $n) { + my $small = isqrt($n +> 2) +< 1; + my $large = $small + 1; + + return $large² > $n ?? $small !! $large; +} diff --git a/challenge-133/james-raspass/raku/ch-2.raku b/challenge-133/james-raspass/raku/ch-2.raku new file mode 100644 index 0000000000..99c9d6ea1c --- /dev/null +++ b/challenge-133/james-raspass/raku/ch-2.raku @@ -0,0 +1,16 @@ +sub factors($n is copy) { + my constant @primes = grep &is-prime, ^∞; + + my $i; + gather while $n > 1 { + next unless $n %% my $factor = @primes[$i++]; + + $i = 0; + $n /= take $factor; + } +} + +multi is-smith (0) { False } +multi is-smith { !$^n.is-prime && $n.comb.sum == factors($n).comb.sum } + +grep(&is-smith, ^∞)[^10].say; |
