From e658f5c0aa5f41c468d60e1a62779b3cbb96412e Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Wed, 3 Apr 2019 15:15:25 -0400 Subject: Added solution for challenge-001. --- challenge-001/adam-russell/README | 1 + challenge-001/adam-russell/blog.txt | 1 + challenge-001/adam-russell/perl5/ch-1.pl | 12 ++++++++++++ challenge-001/adam-russell/perl5/ch-2.pl | 28 ++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 challenge-001/adam-russell/README create mode 100644 challenge-001/adam-russell/blog.txt create mode 100644 challenge-001/adam-russell/perl5/ch-1.pl create mode 100644 challenge-001/adam-russell/perl5/ch-2.pl diff --git a/challenge-001/adam-russell/README b/challenge-001/adam-russell/README new file mode 100644 index 0000000000..9420c9a781 --- /dev/null +++ b/challenge-001/adam-russell/README @@ -0,0 +1 @@ +Solution by Adam Russell diff --git a/challenge-001/adam-russell/blog.txt b/challenge-001/adam-russell/blog.txt new file mode 100644 index 0000000000..80290c5b2a --- /dev/null +++ b/challenge-001/adam-russell/blog.txt @@ -0,0 +1 @@ +https://adamcrussell.livejournal.com/269.html diff --git a/challenge-001/adam-russell/perl5/ch-1.pl b/challenge-001/adam-russell/perl5/ch-1.pl new file mode 100644 index 0000000000..ff50d0f18d --- /dev/null +++ b/challenge-001/adam-russell/perl5/ch-1.pl @@ -0,0 +1,12 @@ +use strict; +use warnings; +## +# 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. +## +my $challenge_string="Perl Weekly Challenge"; +my $number=do{ + $challenge_string=~tr/e/E/ +}; +print "$number $challenge_string\n"; diff --git a/challenge-001/adam-russell/perl5/ch-2.pl b/challenge-001/adam-russell/perl5/ch-2.pl new file mode 100644 index 0000000000..e2671d51f8 --- /dev/null +++ b/challenge-001/adam-russell/perl5/ch-2.pl @@ -0,0 +1,28 @@ +use strict; +use warnings; +## +# Challenge #2 +# Write one-liner to solve FizzBuzz problem and print number 1-20. +# However, any number divisible by 3 should be replaced by the word fizz +# and any divisible by 5 by the word buzz. Numbers divisible by both become fizz buzz. +## +use experimental q/switch/; +my $i = 1; +{ + given($i){ + when($i % 3 == 0 && $i % 5 == 0){ + print "fizz buzz\n"; + } + when($i % 5 == 0){ + print "buzz\n"; + } + when($i % 3 == 0){ + print "fizz\n"; + } + default{ + print "$i\n"; + } + } + $i++; + redo until ($i > 20); +} -- cgit