aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-01-18 18:18:08 +0000
committerGitHub <noreply@github.com>2022-01-18 18:18:08 +0000
commit1ab4e4eb4677fe45bd807ef634ac7a376f181cff (patch)
tree4afb37cf3e5120083ecf4d1df1b4367a4cbec900
parent6f68cef5b1366f136a61590e2c6f3473f0bc2eb7 (diff)
parent06454b81e81fa410ed73dcbf50ed2256968d0371 (diff)
downloadperlweeklychallenge-club-1ab4e4eb4677fe45bd807ef634ac7a376f181cff.tar.gz
perlweeklychallenge-club-1ab4e4eb4677fe45bd807ef634ac7a376f181cff.tar.bz2
perlweeklychallenge-club-1ab4e4eb4677fe45bd807ef634ac7a376f181cff.zip
Merge pull request #5539 from 2colours/branch-for-challenge-148
Added solutions for challenge #148
-rwxr-xr-xchallenge-148/2colours/raku/ch-1.raku9
-rwxr-xr-xchallenge-148/2colours/raku/ch-2.raku17
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-148/2colours/raku/ch-1.raku b/challenge-148/2colours/raku/ch-1.raku
new file mode 100755
index 0000000000..a88dd8841e
--- /dev/null
+++ b/challenge-148/2colours/raku/ch-1.raku
@@ -0,0 +1,9 @@
+#!/usr/bin/env raku
+
+constant @small-contains-e = 1, 3, 5, 7, 8, 9, 10, 11, 12;
+constant @xties-contains-e = 2, 7, 8, 9;
+multi is-eban($num where 0 < * <= 12) { $num !(elem) @small-contains-e }
+multi is-eban($num where 13 <= * < 20) { False }
+multi is-eban($num where 20 <= * < 100) { $num div 10 !(elem) @xties-contains-e and $num%%10 || is-eban($num%10) }
+
+say (1..^100).grep(&is-eban);
diff --git a/challenge-148/2colours/raku/ch-2.raku b/challenge-148/2colours/raku/ch-2.raku
new file mode 100755
index 0000000000..8fb3b5e51d
--- /dev/null
+++ b/challenge-148/2colours/raku/ch-2.raku
@@ -0,0 +1,17 @@
+#!/usr/bin/env raku
+
+sub cardano-sum($a, $b, $c) {
+ ($a+$b*$c**0.5 andthen .sign*.abs**(1/3))+($a-$b*$c**0.5 andthen .sign*.abs**(1/3))
+}
+
+
+my $cardano-triplets = gather {
+ for 1..Inf -> $biggest {
+ for 1..$biggest -> $mid {
+ for 1..$mid -> $smallest {
+ .take if cardano-sum(|$_) =~= 1 for permutations(($biggest, $mid, $smallest));
+ }
+ }
+ }
+}
+.join(" ").say for $cardano-triplets.head(5);