diff options
| author | James Raspass <jraspass@gmail.com> | 2021-10-05 02:43:23 +0100 |
|---|---|---|
| committer | James Raspass <jraspass@gmail.com> | 2021-10-05 02:43:43 +0100 |
| commit | efc2a3cfabe2050fb9251ecbce949a2a50a643d0 (patch) | |
| tree | 4f4032ea72c2f000985716c3df9070a7477a5245 | |
| parent | 23b1c0c5072b04625971f51aec2ff02d6ab672fe (diff) | |
| download | perlweeklychallenge-club-efc2a3cfabe2050fb9251ecbce949a2a50a643d0.tar.gz perlweeklychallenge-club-efc2a3cfabe2050fb9251ecbce949a2a50a643d0.tar.bz2 perlweeklychallenge-club-efc2a3cfabe2050fb9251ecbce949a2a50a643d0.zip | |
133 JRaspass
$large² and ^∞ are fun uses of unicode imo.
| -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; |
