diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2020-12-27 21:14:45 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2020-12-27 21:14:45 +0000 |
| commit | fdf1a0e3be22cd785e59d729cdb5cff48623de88 (patch) | |
| tree | a50595a92c82c860e10516f1d6e7633308ae49a7 | |
| parent | da2cc800f5a09ef4c7c00fd611da5c56b640a831 (diff) | |
| download | perlweeklychallenge-club-fdf1a0e3be22cd785e59d729cdb5cff48623de88.tar.gz perlweeklychallenge-club-fdf1a0e3be22cd785e59d729cdb5cff48623de88.tar.bz2 perlweeklychallenge-club-fdf1a0e3be22cd785e59d729cdb5cff48623de88.zip | |
Add Perl solution to challenge 001
| -rw-r--r-- | challenge-001/paulo-custodio/README | 1 | ||||
| -rw-r--r-- | challenge-001/paulo-custodio/perl/ch-1.pl | 14 | ||||
| -rw-r--r-- | challenge-001/paulo-custodio/perl/ch-2.pl | 12 | ||||
| -rw-r--r-- | challenge-001/paulo-custodio/test.pl | 41 |
4 files changed, 68 insertions, 0 deletions
diff --git a/challenge-001/paulo-custodio/README b/challenge-001/paulo-custodio/README new file mode 100644 index 0000000000..87dc0b2fbd --- /dev/null +++ b/challenge-001/paulo-custodio/README @@ -0,0 +1 @@ +Solution by Paulo Custodio diff --git a/challenge-001/paulo-custodio/perl/ch-1.pl b/challenge-001/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..37593c4a80 --- /dev/null +++ b/challenge-001/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl + +# Challenge 001 +# +# Challenge #1 +# Write a script to replace the character ‘e’ with ‘E’ in the string ‘Perl Weekly Challenge’. Also print the number of times the character ‘e’ is found in the string. + +use strict; +use warnings; +use 5.030; + +my $s = "Perl Weekly Challenge"; +say(($s =~ tr/e/E/), " ", $s); + diff --git a/challenge-001/paulo-custodio/perl/ch-2.pl b/challenge-001/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..3c799efd39 --- /dev/null +++ b/challenge-001/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl + +# Challenge 001 +# +# Challenge #2 +# Write a one-liner to solve the FizzBuzz problem and print the numbers 1 through 20. However, any number divisible by 3 should be replaced by the word ‘fizz’ and any divisible by 5 by the word ‘buzz’. Those numbers that are both divisible by 3 and 5 become ‘fizzbuzz’. + +use strict; +use warnings; +use 5.030; + +for (1..20) { say(($_%3)==0 && ($_%5)==0 ? "fizzbuzz" : ($_%3)==0 ? "fizz" : ($_%5)==0 ? "buzz" : $_) } diff --git a/challenge-001/paulo-custodio/test.pl b/challenge-001/paulo-custodio/test.pl new file mode 100644 index 0000000000..8b2d3f4625 --- /dev/null +++ b/challenge-001/paulo-custodio/test.pl @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; +use 5.030; + +is capture("perl perl/ch-1.pl"), "5 PErl WEEkly ChallEngE\n"; + +is capture("perl perl/ch-2.pl"), <<END; +1 +2 +fizz +4 +buzz +fizz +7 +8 +fizz +buzz +11 +fizz +13 +14 +fizzbuzz +16 +17 +fizz +19 +buzz +END + + +done_testing; + +sub capture { + my($cmd) = @_; + my $out = `$cmd`; + $out =~ s/\r//g; + return $out; +} |
