diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2022-04-07 12:13:57 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2022-04-07 12:13:57 +0100 |
| commit | 20cf091dc6f07128d9eeb0c44cce33e1ec590a7b (patch) | |
| tree | 9907b42237df4e21333aa077a153aec49c18fbf6 /challenge-047 | |
| parent | 0ad107e15790dc3ff03feec41446f8781a13883a (diff) | |
| download | perlweeklychallenge-club-20cf091dc6f07128d9eeb0c44cce33e1ec590a7b.tar.gz perlweeklychallenge-club-20cf091dc6f07128d9eeb0c44cce33e1ec590a7b.tar.bz2 perlweeklychallenge-club-20cf091dc6f07128d9eeb0c44cce33e1ec590a7b.zip | |
Add Perl solution to challenge 047
Diffstat (limited to 'challenge-047')
| -rw-r--r-- | challenge-047/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-047/paulo-custodio/README | 1 | ||||
| -rw-r--r-- | challenge-047/paulo-custodio/perl/ch-1.pl | 33 | ||||
| -rw-r--r-- | challenge-047/paulo-custodio/perl/ch-2.pl | 24 | ||||
| -rw-r--r-- | challenge-047/paulo-custodio/t/test-1.yaml | 10 | ||||
| -rw-r--r-- | challenge-047/paulo-custodio/t/test-2.yaml | 5 |
6 files changed, 75 insertions, 0 deletions
diff --git a/challenge-047/paulo-custodio/Makefile b/challenge-047/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-047/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-047/paulo-custodio/README b/challenge-047/paulo-custodio/README new file mode 100644 index 0000000000..87dc0b2fbd --- /dev/null +++ b/challenge-047/paulo-custodio/README @@ -0,0 +1 @@ +Solution by Paulo Custodio diff --git a/challenge-047/paulo-custodio/perl/ch-1.pl b/challenge-047/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..7888c446e3 --- /dev/null +++ b/challenge-047/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +# Challenge 047 +# +# TASK #1 +# Roman Calculator +# Write a script that accepts two roman numbers and operation. It should then +# perform the operation on the give roman numbers and print the result. +# +# For example, +# +# perl ch-1.pl V + VI +# It should print +# +# XI + +use Modern::Perl; +use Math::Roman qw(roman); + +@ARGV==3 or die "Usage: ch-1.pl xxx +- xxx\n"; + +my $a = roman($ARGV[0]); +my $op = $ARGV[1]; +my $b = roman($ARGV[2]); +if ($op eq '+') { + say $a+$b; +} +elsif ($op eq '-') { + say $a-$b; +} +else { + die "invalid operation\n"; +} diff --git a/challenge-047/paulo-custodio/perl/ch-2.pl b/challenge-047/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..d9dd8b3cc0 --- /dev/null +++ b/challenge-047/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env perl + +# 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. + +use Modern::Perl; + +my @out; +my $n = 100; +while (@out < 20) { + push @out, $n if is_gapfull($n); + $n++; +} +say join(", ", @out); + +sub is_gapfull { + my($n) = @_; + my $div = substr($n,0,1).substr($n,-1,1); + return ($n % $div) == 0; +} diff --git a/challenge-047/paulo-custodio/t/test-1.yaml b/challenge-047/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..16bb61a604 --- /dev/null +++ b/challenge-047/paulo-custodio/t/test-1.yaml @@ -0,0 +1,10 @@ +- setup: + cleanup: + args: V + VI + input: + output: XI +- setup: + cleanup: + args: V - II + input: + output: III diff --git a/challenge-047/paulo-custodio/t/test-2.yaml b/challenge-047/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..aa0e359aea --- /dev/null +++ b/challenge-047/paulo-custodio/t/test-2.yaml @@ -0,0 +1,5 @@ +- setup: + cleanup: + args: + input: + output: 100, 105, 108, 110, 120, 121, 130, 132, 135, 140, 143, 150, 154, 160, 165, 170, 176, 180, 187, 190 |
