aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-10-16 13:24:08 +0100
committerGitHub <noreply@github.com>2021-10-16 13:24:08 +0100
commit2e70ee4ef93c28e1c48fbfc452a14f736260f540 (patch)
tree3ddfd9bcc6f9f7a6e587c991bbca55e2dd35cbed
parentdecba73b3de5b0a10c302edcb667ca60c187b021 (diff)
parentb1061f77086e86549d1a13cef90976f2720cf3b6 (diff)
downloadperlweeklychallenge-club-2e70ee4ef93c28e1c48fbfc452a14f736260f540.tar.gz
perlweeklychallenge-club-2e70ee4ef93c28e1c48fbfc452a14f736260f540.tar.bz2
perlweeklychallenge-club-2e70ee4ef93c28e1c48fbfc452a14f736260f540.zip
Merge pull request #5033 from wambash/challenge-week-134
solutions week 134
-rw-r--r--challenge-134/wambash/raku/ch-1.raku20
-rw-r--r--challenge-134/wambash/raku/ch-2.raku26
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-134/wambash/raku/ch-1.raku b/challenge-134/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..2d913e4f42
--- /dev/null
+++ b/challenge-134/wambash/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/env raku
+
+
+sub pandigital-numbers($n=5) {
+ 1,0,slip 2..9
+ andthen .permutations
+ andthen .head($n)
+ andthen .map: *.join
+}
+
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is pandigital-numbers, <1023456789 1023456798 1023456879 1023456897 1023456978>;
+ done-testing;
+}
+
+multi MAIN ($n=5) {
+ .put for pandigital-numbers($n);
+}
diff --git a/challenge-134/wambash/raku/ch-2.raku b/challenge-134/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..f9e1450646
--- /dev/null
+++ b/challenge-134/wambash/raku/ch-2.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+class DistinctTermsCount {
+ has Int $.m;
+ has Int $.n;
+
+ has $.table;
+ has $.distinct-terms handles count => <elems>;
+
+ submethod TWEAK () {
+ with (1..$!m X* 1..$!n).cache {
+ $!table := .batch(3);
+ $!distinct-terms := .unique;
+ }
+ }
+}
+
+multi MAIN (Bool :test($)!){
+ use Test;
+ is-deeply DistinctTermsCount.new(:3m,:3n).table, ((1,2,3),(2,4,6),(3,6,9));
+ is DistinctTermsCount.new(:3m,:3n).distinct-terms, <1 2 3 4 6 9>;
+ is DistinctTermsCount.new(:3m,:3n).count, 6;
+ is DistinctTermsCount.new(:3m,:5n).distinct-terms, <1 2 3 4 5 6 8 10 9 12 15>;
+ is DistinctTermsCount.new(:3m,:5n).count, 11;
+ done-testing;
+}