diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2020-02-10 10:28:22 +0100 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2020-02-10 10:49:24 +0100 |
| commit | f5efeb8fd0e55468666547495a5d8189f9c74084 (patch) | |
| tree | 0224151eb06805ce934437637965b02ea0f0d020 | |
| parent | ea32be64d34ed2a25cfdb3167dee07e4dbc5c6ce (diff) | |
| download | perlweeklychallenge-club-f5efeb8fd0e55468666547495a5d8189f9c74084.tar.gz perlweeklychallenge-club-f5efeb8fd0e55468666547495a5d8189f9c74084.tar.bz2 perlweeklychallenge-club-f5efeb8fd0e55468666547495a5d8189f9c74084.zip | |
Task 2 done.
| -rw-r--r-- | challenge-047/luca-ferrari/raku/ch-2.p6 | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-047/luca-ferrari/raku/ch-2.p6 b/challenge-047/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..124b4e924c --- /dev/null +++ b/challenge-047/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,30 @@ +#!env raku +# +# Perl Weekly Challenge 47 +# see <https://perlweeklychallenge.org/blog/perl-weekly-challenge-047/> +# +# Task 2 +# Gapful Number +# +# Write a script to print first 20 Gapful Numbers greater than or equal to 100. +# Please check out the page for more information about Gapful Numbers. +# From <https://oeis.org/A108343> +# Gapful numbers >= 100: numbers that are divisible by the number +# formed by their first and last digit. +# Numbers up to 100 trivially have this property and are excluded. + + + +sub MAIN( Int:D :$limit = 20 ) { + + my @found; + for 100 .. Inf { + $_ ~~ / ^ $<first>=\d \d+ $<last>=\d $ /; + my $divisor = ( $/<first> ~ $/<last> ).Int; + @found.push: $divisor if $_ %% $divisor && ! @found.grep: { $_ == $divisor }; + last if @found.elems == $limit; + } + + "Here it is what I found, first $limit Gapful Numbers:\n".say; + @found.sort.join( "\n\t" ).say; +} |
