diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-02-16 23:49:19 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-02-16 23:49:19 +0000 |
| commit | ec2de2ac1b6b94fc0abeac5ec1294536ef39824f (patch) | |
| tree | 09e7104ab9db8805c5c30ec65c2c6f1bb50cac13 /challenge-047 | |
| parent | 7724552a38ed1cdb72993999fc30f9e979e903eb (diff) | |
| download | perlweeklychallenge-club-ec2de2ac1b6b94fc0abeac5ec1294536ef39824f.tar.gz perlweeklychallenge-club-ec2de2ac1b6b94fc0abeac5ec1294536ef39824f.tar.bz2 perlweeklychallenge-club-ec2de2ac1b6b94fc0abeac5ec1294536ef39824f.zip | |
- Added solutions by Colin Crain.
Diffstat (limited to 'challenge-047')
| -rw-r--r-- | challenge-047/colin-crain/perl/ch-2.pl | 41 | ||||
| -rw-r--r-- | challenge-047/colin-crain/raku/ch-2.p6 | 37 |
2 files changed, 78 insertions, 0 deletions
diff --git a/challenge-047/colin-crain/perl/ch-2.pl b/challenge-047/colin-crain/perl/ch-2.pl new file mode 100644 index 0000000000..34b66b58fe --- /dev/null +++ b/challenge-047/colin-crain/perl/ch-2.pl @@ -0,0 +1,41 @@ +#! /opt/local/bin/perl +# +# gapful.pl +# + +# PWC 47 - 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. +# +# 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. +# +# 100, 105, 108, 110, 120, 121, 130, 132, 135, 140, 143, 150, +# 154, 160, 165, 170, 176, 180, 187, 190, 192, 195, 198, 200, +# 220, 225, 231, 240, 242, 253, 260, 264, 275, 280, 286, 297, +# 300, 315, 330, 341, 352, 360, 363, 374, 385, 390, 396, 400, +# 405, 440, 451 +# +# 2020 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +use warnings; +use strict; +use feature ":5.26"; + +## ## ## ## ## MAIN + +my $testval = 99; +my @output; + +while (scalar @output < 20 && $testval++ ) { + my $gap = substr( $testval, 0, 1 ) . substr( $testval, -1, 1 ); + push @output, $testval if $testval % $gap == 0; +} +say for @output; diff --git a/challenge-047/colin-crain/raku/ch-2.p6 b/challenge-047/colin-crain/raku/ch-2.p6 new file mode 100644 index 0000000000..f0c6a0f75b --- /dev/null +++ b/challenge-047/colin-crain/raku/ch-2.p6 @@ -0,0 +1,37 @@ +use v6.d; + +# +# gapful.raku +# +# PWC 47 - 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. +# +# 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. +# +# 100, 105, 108, 110, 120, 121, 130, 132, 135, 140, 143, 150, +# 154, 160, 165, 170, 176, 180, 187, 190, 192, 195, 198, 200, +# 220, 225, 231, 240, 242, 253, 260, 264, 275, 280, 286, 297, +# 300, 315, 330, 341, 352, 360, 363, 374, 385, 390, 396, 400, +# 405, 440, 451 +# +# 2020 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + +sub MAIN () { + + ## this parses to literally exactly the definition of A108343 above; allow + ## only numbers (starting at 100) "that are divisible by the number formed by + ## their first and last digit"". + + my @o2 = (100..*).grep({ $_ %% (.comb.head ~ .comb.tail) }); + + ## output creates the first required 20 elements of the lazy list + say @o2[$_] for (0..19); + +} |
