diff options
| -rw-r--r-- | challenge-067/luca-ferrari/blog-1.txt | 1 | ||||
| -rw-r--r-- | challenge-067/luca-ferrari/blog-2.txt | 1 | ||||
| -rw-r--r-- | challenge-067/luca-ferrari/raku/ch-1.p6 | 27 | ||||
| -rw-r--r-- | challenge-067/luca-ferrari/raku/ch-2.p6 | 25 |
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; +} |
