diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2023-03-30 18:07:55 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2023-03-30 18:07:55 +0100 |
| commit | 5ef98977a52bbad4c934d7d6337caedb4384e918 (patch) | |
| tree | 17ab7b3b698b91eb42c2902a0ebb8c405d40ebe4 | |
| parent | a8e47ee7f95315cc91d4c071d24b6fded01cb9ce (diff) | |
| download | perlweeklychallenge-club-5ef98977a52bbad4c934d7d6337caedb4384e918.tar.gz perlweeklychallenge-club-5ef98977a52bbad4c934d7d6337caedb4384e918.tar.bz2 perlweeklychallenge-club-5ef98977a52bbad4c934d7d6337caedb4384e918.zip | |
Add Perl solution
| -rw-r--r-- | challenge-173/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-173/paulo-custodio/perl/ch-1.pl | 34 | ||||
| -rw-r--r-- | challenge-173/paulo-custodio/perl/ch-2.pl | 39 | ||||
| -rw-r--r-- | challenge-173/paulo-custodio/t/test-1.yaml | 10 | ||||
| -rw-r--r-- | challenge-173/paulo-custodio/t/test-2.yaml | 5 |
5 files changed, 90 insertions, 0 deletions
diff --git a/challenge-173/paulo-custodio/Makefile b/challenge-173/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-173/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-173/paulo-custodio/perl/ch-1.pl b/challenge-173/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..caba1bf96d --- /dev/null +++ b/challenge-173/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +# Challenge 173 +# +# Task 1: Esthetic Number +# Submitted by: Mohammad S Anwar +# +# You are given a positive integer, $n. +# +# Write a script to find out if the given number is Esthetic Number. +# +# An esthetic number is a positive integer where every adjacent digit differs +# from its neighbour by 1. +# +# +# For example, +# +# 5456 is an esthetic number as |5 - 4| = |4 - 5| = |5 - 6| = 1 +# 120 is not an esthetic numner as |1 - 2| != |2 - 0| != 1 + +use Modern::Perl; + +sub is_esthetic { + my($n) = @_; + my @n = split //, $n; + while (@n > 1) { + return 0 if abs($n[0] - $n[1]) != 1; + shift @n; + } + return 1; +} + +@ARGV==1 or die "usage: ch-1.pl n\n"; +say is_esthetic(shift); diff --git a/challenge-173/paulo-custodio/perl/ch-2.pl b/challenge-173/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..34eb742026 --- /dev/null +++ b/challenge-173/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl + +# Challenge 173 +# +# Task 2: Sylvester’s sequence +# Submitted by: Mohammad S Anwar +# +# Write a script to generate first 10 members of Sylvester's sequence. For more +# informations, please refer to the wikipedia page. +# +# Output +# +# 2 +# 3 +# 7 +# 43 +# 1807 +# 3263443 +# 10650056950807 +# 113423713055421844361000443 +# 12864938683278671740537145998360961546653259485195807 +# 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443 + +use Modern::Perl; + +sub sylvester_seq { + my($N) = @_; + my @n = (2); + my $prod = 2; + while (@n < $N) { + my $term = $prod+1; + push @n, $term; + $prod *= $term; + } + return @n; +} + +@ARGV==1 or die "usage: ch-2.pl n\n"; +say join ", ", sylvester_seq(shift); diff --git a/challenge-173/paulo-custodio/t/test-1.yaml b/challenge-173/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..a5a1d6d39d --- /dev/null +++ b/challenge-173/paulo-custodio/t/test-1.yaml @@ -0,0 +1,10 @@ +- setup: + cleanup: + args: 5456 + input: + output: 1 +- setup: + cleanup: + args: 120 + input: + output: 0 diff --git a/challenge-173/paulo-custodio/t/test-2.yaml b/challenge-173/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..7adc9b3a5a --- /dev/null +++ b/challenge-173/paulo-custodio/t/test-2.yaml @@ -0,0 +1,5 @@ +- setup: + cleanup: + args: 7 + input: + output: 2, 3, 7, 43, 1807, 3263443, 10650056950807 |
