diff options
| author | Polgár Márton <polgar@astron.hu> | 2022-06-19 19:39:17 +0200 |
|---|---|---|
| committer | Polgár Márton <polgar@astron.hu> | 2022-06-19 19:39:17 +0200 |
| commit | f7a60044c57e0eb8ad1ce764c3ddc9e7e6576bd7 (patch) | |
| tree | 7db5bfa0563f7a0e8531574178e22520d16f46e2 | |
| parent | df02ef242fdabe5f882bb977d658b612adf95621 (diff) | |
| download | perlweeklychallenge-club-f7a60044c57e0eb8ad1ce764c3ddc9e7e6576bd7.tar.gz perlweeklychallenge-club-f7a60044c57e0eb8ad1ce764c3ddc9e7e6576bd7.tar.bz2 perlweeklychallenge-club-f7a60044c57e0eb8ad1ce764c3ddc9e7e6576bd7.zip | |
Weekly solutions by 2colours
| -rwxr-xr-x | challenge-169/2colours/raku/ch-1.raku | 19 | ||||
| -rwxr-xr-x | challenge-169/2colours/raku/ch-2.raku | 20 |
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-169/2colours/raku/ch-1.raku b/challenge-169/2colours/raku/ch-1.raku new file mode 100755 index 0000000000..a17ab34df7 --- /dev/null +++ b/challenge-169/2colours/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + + +my @primes = grep &is-prime, ^Inf; +my @primes-digited = @primes.map( -> $current { + state @buffer; + when @buffer[0] andthen .chars == $current.chars { + @buffer.append: $current; + Empty + } + my @res = @buffer; + @buffer = [$current]; + @res +}); +@primes-digited .= skip; +@primes-digited.map({ ([\,] @$_) >>*>> @$_ andthen .flat.sort.Slip }) + andthen .head: 20 + andthen .join: ', ' + andthen .say; diff --git a/challenge-169/2colours/raku/ch-2.raku b/challenge-169/2colours/raku/ch-2.raku new file mode 100755 index 0000000000..1fa0bc027d --- /dev/null +++ b/challenge-169/2colours/raku/ch-2.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +sub is-achilles($num) { + (powerful-exponent($num) // 0) == 1 +} + +multi powerful-exponent(1 --> 0) {} +multi powerful-exponent($ where *.is-prime --> Nil) {} +multi powerful-exponent($num) { + my $first-divisor = (2 .. *).first: $num %% *; + my $first-exponent = (1 .. *).toggle($num %% $first-divisor ** *).tail; + return Nil if $first-exponent == 1; + return $first-exponent gcd $_ with powerful-exponent($num div $first-divisor ** $first-exponent); + Nil +} + +(1 .. *).grep: &is-achilles + andthen .head: 20 + andthen .join: ', ' + andthen .say;
\ No newline at end of file |
