From efc2a3cfabe2050fb9251ecbce949a2a50a643d0 Mon Sep 17 00:00:00 2001 From: James Raspass Date: Tue, 5 Oct 2021 02:43:23 +0100 Subject: 133 JRaspass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $large² and ^∞ are fun uses of unicode imo. --- challenge-133/james-raspass/raku/ch-1.raku | 9 +++++++++ challenge-133/james-raspass/raku/ch-2.raku | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 challenge-133/james-raspass/raku/ch-1.raku create mode 100644 challenge-133/james-raspass/raku/ch-2.raku 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; -- cgit