aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-001/andrezgz/README1
-rw-r--r--challenge-001/andrezgz/perl5/ch-1.pl14
-rw-r--r--challenge-001/andrezgz/perl5/ch-2.sh47
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)
+'