aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-06-29 13:12:53 +0100
committerGitHub <noreply@github.com>2020-06-29 13:12:53 +0100
commit52d15e90e5bf10391a3e9806b7e0ab18f91f1008 (patch)
tree442b6d9d1fadfca4fdbbb9036b9f4f80b232e857
parente7f6940cf0444c185d6e7a94ead2e26cb95f673c (diff)
parent9c185dffa7f9568cad642076729b93d3e1011168 (diff)
downloadperlweeklychallenge-club-52d15e90e5bf10391a3e9806b7e0ab18f91f1008.tar.gz
perlweeklychallenge-club-52d15e90e5bf10391a3e9806b7e0ab18f91f1008.tar.bz2
perlweeklychallenge-club-52d15e90e5bf10391a3e9806b7e0ab18f91f1008.zip
Merge pull request #1885 from fluca1978/pwc67
Pwc67
-rw-r--r--challenge-067/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-067/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-067/luca-ferrari/raku/ch-1.p627
-rw-r--r--challenge-067/luca-ferrari/raku/ch-2.p625
4 files changed, 54 insertions, 0 deletions
diff --git a/challenge-067/luca-ferrari/blog-1.txt b/challenge-067/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..53886516ee
--- /dev/null
+++ b/challenge-067/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/06/29/PerlWeeklyChallenge67.html#task1
diff --git a/challenge-067/luca-ferrari/blog-2.txt b/challenge-067/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..f4a8e9f455
--- /dev/null
+++ b/challenge-067/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/06/29/PerlWeeklyChallenge67.html#task2
diff --git a/challenge-067/luca-ferrari/raku/ch-1.p6 b/challenge-067/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..ed10fbdcee
--- /dev/null
+++ b/challenge-067/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,27 @@
+#!raku
+
+# Task 1
+# You are given two integers $m and $n. Write a script print all possible combinations of $n numbers from the list 1 2 3 … $m.
+#
+# Every combination should be sorted i.e. [2,3] is valid combination but [3,2] is not.
+
+
+sub MAIN( Int :$m where { 10 > $m > 2 } = 5,
+ Int :$n where { $n < $m } = 2 ) {
+
+ # found combinations
+ my @combinations;
+
+
+ for ( 1 x $n ).Int ^..^ ( $m x $n ).Int {
+ my @digits = $_.comb;
+ next if @digits.elems != $n;
+ next if @digits.grep( * > $m );
+ my $ok = True;
+ $ok = False if ( @digits[ $_ ] >= @digits[ $_ + 1 ] ) for 0 ..^ @digits.elems - 1;
+ @combinations.push: @digits if $ok;
+ }
+
+
+ @combinations.sort.join( ", " ).say;
+}
diff --git a/challenge-067/luca-ferrari/raku/ch-2.p6 b/challenge-067/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..e414b630db
--- /dev/null
+++ b/challenge-067/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,25 @@
+#!raku
+
+# Task 2
+# You are given a digit string $S. Write a script to print all possible letter combinations that the given digit string could represent.
+
+
+sub MAIN( Str $S ) {
+ my %letters =
+ 1 => [ '_', ',', '@' ]
+ , 2 => [ 'A', 'B', 'C' ]
+ , 3 => [ 'D', 'E', 'F' ]
+ , 4 => [ 'G', 'H', 'I' ]
+ , 5 => [ 'J', 'K', 'L' ]
+ , 6 => [ 'M', 'N', 'O' ]
+ , 7 => [ 'P', 'Q', 'R', 'S' ]
+ , 8 => [ 'T', 'U', 'V' ]
+ , 9 => [ 'W', 'X', 'Y', 'Z' ];
+
+ my @combinations;
+ for $S.comb -> $current {
+ @combinations.push( %letters{ $current } ) if %letters{ $current }:exists;
+ }
+
+ ( [X] @combinations ).join( "\n" ).lc.say;
+}