diff options
| -rw-r--r-- | challenge-065/luca-ferrari/raku/ch-1.p6 | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-065/luca-ferrari/raku/ch-1.p6 b/challenge-065/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..c1337e9fbd --- /dev/null +++ b/challenge-065/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,30 @@ +#!raku + +# You are given two positive numbers $N and $S. +# +# Write a script to list all positive numbers having +# exactly $N digits where sum of all digits equals to $S. +# Example +# +# Input: +# $N = 2 +# $S = 4 +# +# Output: +# 13, 22, 31, 40 + + + +sub MAIN( Int $N where { $N > 0 }, + Int $S where { $S > 0 } ) { + + + my @found; + "Searching numbers with $N digits that sum to $S between { 1 ~ ( 0 x $N - 1 ) } and { $S ~ ( 0 x $N - 1 ) }".say; + for ( 1 ~ ( 0 x $N - 1 ) ).Int .. ( $S ~ ( 0 x $N - 1 ) ).Int { + @found.push: $_ if ( [+] $_.split( '', :skip-empty ) ) == $S ; + } + + @found.say; + +} |
