aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-169/2colours/raku/ch-1.raku19
-rwxr-xr-xchallenge-169/2colours/raku/ch-2.raku20
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