aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2022-07-17 13:43:27 -0400
committerDave Jacoby <jacoby.david@gmail.com>2022-07-17 13:43:27 -0400
commit1431c089150cad1bc1abf6f0b7589b5ae06aed50 (patch)
tree3bc4f2444fc231d89703e970b13153024a8d9a64
parentda59df31935c1c8a195be752281f12aa17dac146 (diff)
downloadperlweeklychallenge-club-1431c089150cad1bc1abf6f0b7589b5ae06aed50.tar.gz
perlweeklychallenge-club-1431c089150cad1bc1abf6f0b7589b5ae06aed50.tar.bz2
perlweeklychallenge-club-1431c089150cad1bc1abf6f0b7589b5ae06aed50.zip
DAJ 173
-rw-r--r--challenge-173/dave-jacoby/perl/ch-1.pl23
-rw-r--r--challenge-173/dave-jacoby/perl/ch-2.pl20
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;