diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2020-05-11 08:46:31 +0200 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2020-05-11 08:46:31 +0200 |
| commit | d43a46c6e7193b40c1ea7ca38adcef829bc8f3b9 (patch) | |
| tree | b89ec956007462514402461fa70c4d9363bf6651 | |
| parent | 72befa7c5d2de9e9a9029baccb6d49d81b5dd9db (diff) | |
| download | perlweeklychallenge-club-d43a46c6e7193b40c1ea7ca38adcef829bc8f3b9.tar.gz perlweeklychallenge-club-d43a46c6e7193b40c1ea7ca38adcef829bc8f3b9.tar.bz2 perlweeklychallenge-club-d43a46c6e7193b40c1ea7ca38adcef829bc8f3b9.zip | |
Task 2 done.
| -rw-r--r-- | challenge-060/luca-ferrari/raku/ch-2.p6 | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-060/luca-ferrari/raku/ch-2.p6 b/challenge-060/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..72d024e444 --- /dev/null +++ b/challenge-060/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,42 @@ +#!env raku + + + + +# Write a script that accepts list of positive numbers (@L) and two positive numbers $X and $Y. +# +# The script should print all possible numbers made by concatenating +# the numbers from @L, whose length is exactly $X +# but value is less than $Y. +# Example +# +# Input: +# +# @L = (0, 1, 2, 5); +# $X = 2; +# $Y = 21; +# +# Output: +# +# 10, 11, 12, 15, 20 + + + +sub MAIN ( ){ + my @L = (0, 1, 2, 5); + my $x = 2; + my $y = 21; + my @LL; + + # start from the very beginning of the list limiting + # the numbers in the range of $y + for ( 1 x $x ) - 1 ..^ $y { + + # see if the numbers "grep" the list + my $found = 0; + $found++ if $_ == any( @L ) for $_.comb; + @LL.push: $_ if $_.comb.elems == $found; + } + + say @LL.join( ', ' ); +} |
