diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-07-17 18:49:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-17 18:49:18 +0100 |
| commit | d0d8d5323bd1ca85639a089c4f536b595b1cd5f9 (patch) | |
| tree | 3bc4f2444fc231d89703e970b13153024a8d9a64 | |
| parent | da59df31935c1c8a195be752281f12aa17dac146 (diff) | |
| parent | 1431c089150cad1bc1abf6f0b7589b5ae06aed50 (diff) | |
| download | perlweeklychallenge-club-d0d8d5323bd1ca85639a089c4f536b595b1cd5f9.tar.gz perlweeklychallenge-club-d0d8d5323bd1ca85639a089c4f536b595b1cd5f9.tar.bz2 perlweeklychallenge-club-d0d8d5323bd1ca85639a089c4f536b595b1cd5f9.zip | |
Merge pull request #6456 from jacoby/master
DAJ 173
| -rw-r--r-- | challenge-173/dave-jacoby/perl/ch-1.pl | 23 | ||||
| -rw-r--r-- | challenge-173/dave-jacoby/perl/ch-2.pl | 20 |
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-173/dave-jacoby/perl/ch-1.pl b/challenge-173/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..388f4a83ff --- /dev/null +++ b/challenge-173/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +my @numbers = ( 5456, 120, 123 ); + +for my $n (@numbers) { + my $str = 'is not an esthetic number '; + if ( is_esthetic($n) ) { $str = 'is an esthetic number ' } + say qq{ $n $str}; +} + +sub is_esthetic($n) { + my @n = split //, $n; + for my $i ( 1 .. -1 + scalar @n ) { + my $j = $i - 1; + my $e = abs $n[$i] - $n[$j]; + return 0 if $e != 1; + } + return 1; +} diff --git a/challenge-173/dave-jacoby/perl/ch-2.pl b/challenge-173/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..854751c70d --- /dev/null +++ b/challenge-173/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +# this looks like a job for iteration + +use List::Util qw{ product }; +use Math::BigInt; + +# Did I mention that I like Math::BigInt? + +my @n = map { Math::BigInt->new($_) } ( 2, 3 ); + +while ( scalar @n < 10 ) { + my $x = Math::BigInt->bone();; + push @n, 1 + product @n ; +} +say join "\n ", '', @n; |
