diff options
| author | agimenez <agimenez@educativa.com> | 2019-04-03 21:12:58 -0300 |
|---|---|---|
| committer | agimenez <agimenez@educativa.com> | 2019-04-03 21:12:58 -0300 |
| commit | aa2d8f2c52a73a2980a13e24e5aba083ee35ef63 (patch) | |
| tree | 35ae7926a6d7c3825f0664e846726a3c6e63011e /challenge-001 | |
| parent | 9806a0cead89d364cf0b5ec1e01459eb372a77d2 (diff) | |
| download | perlweeklychallenge-club-aa2d8f2c52a73a2980a13e24e5aba083ee35ef63.tar.gz perlweeklychallenge-club-aa2d8f2c52a73a2980a13e24e5aba083ee35ef63.tar.bz2 perlweeklychallenge-club-aa2d8f2c52a73a2980a13e24e5aba083ee35ef63.zip | |
Solution challenge-001 andrezgz
Diffstat (limited to 'challenge-001')
| -rw-r--r-- | challenge-001/andrezgz/README | 1 | ||||
| -rw-r--r-- | challenge-001/andrezgz/perl5/ch-1.pl | 14 | ||||
| -rw-r--r-- | challenge-001/andrezgz/perl5/ch-2.sh | 47 |
3 files changed, 62 insertions, 0 deletions
diff --git a/challenge-001/andrezgz/README b/challenge-001/andrezgz/README new file mode 100644 index 0000000000..f4fd0da88e --- /dev/null +++ b/challenge-001/andrezgz/README @@ -0,0 +1 @@ +Solution by Andrezgz diff --git a/challenge-001/andrezgz/perl5/ch-1.pl b/challenge-001/andrezgz/perl5/ch-1.pl new file mode 100644 index 0000000000..c39458af73 --- /dev/null +++ b/challenge-001/andrezgz/perl5/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/a-new-week-a-new-challenge/ +# 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’ found in the string. + +use strict; + +my $str = 'Perl Weekly Challenge'; + +my $c = ($str =~ tr/e/E/); + +print $str . ' had ' . $c . ' e\'s that were replaced by E\'s'; diff --git a/challenge-001/andrezgz/perl5/ch-2.sh b/challenge-001/andrezgz/perl5/ch-2.sh new file mode 100644 index 0000000000..e3471a0222 --- /dev/null +++ b/challenge-001/andrezgz/perl5/ch-2.sh @@ -0,0 +1,47 @@ +# https://perlweeklychallenge.org/blog/a-new-week-a-new-challenge/ +# 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’. + + +perl -e ' + map { + print ( + (!($_ % 15) + ? "fizzbuzz" + : !($_ % 3) + ? "fizz" + : !($_ % 5) + ? "buzz" + : $_) + . "\n" + ) + } (1..20) +' + +perl -e ' + map { + print ( + (!($_ % 15) + ? "fizzbuzz" : "" + .!($_ % 3) + ? "fizz" : "" + .!($_ % 5) + ? "buzz" : "" + . $_) + . $/ + ) + } (1..20) +' + + +perl -e ' + print join $/, map { + my $d = $_; + $_ = "fizz" unless ($d % 3); + $_ = "buzz" unless ($d % 5); + $_ = "fizzbuzz" unless ($d % 15); + $_ + } (1..20) +' |
