From d43a46c6e7193b40c1ea7ca38adcef829bc8f3b9 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 11 May 2020 08:46:31 +0200 Subject: Task 2 done. --- challenge-060/luca-ferrari/raku/ch-2.p6 | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 challenge-060/luca-ferrari/raku/ch-2.p6 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( ', ' ); +} -- cgit