diff options
| author | Adam Russell <adam.russell@optum.com> | 2019-04-03 15:15:25 -0400 |
|---|---|---|
| committer | Adam Russell <adam.russell@optum.com> | 2019-04-03 15:15:25 -0400 |
| commit | e658f5c0aa5f41c468d60e1a62779b3cbb96412e (patch) | |
| tree | 6be3783563a694c06cf2150d7350d9aa4fe2aea5 /challenge-001 | |
| parent | b0ebc4d44401cf8751be27da5b2454acd75538fe (diff) | |
| download | perlweeklychallenge-club-e658f5c0aa5f41c468d60e1a62779b3cbb96412e.tar.gz perlweeklychallenge-club-e658f5c0aa5f41c468d60e1a62779b3cbb96412e.tar.bz2 perlweeklychallenge-club-e658f5c0aa5f41c468d60e1a62779b3cbb96412e.zip | |
Added solution for challenge-001.
Diffstat (limited to 'challenge-001')
| -rw-r--r-- | challenge-001/adam-russell/README | 1 | ||||
| -rw-r--r-- | challenge-001/adam-russell/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-001/adam-russell/perl5/ch-1.pl | 12 | ||||
| -rw-r--r-- | challenge-001/adam-russell/perl5/ch-2.pl | 28 |
4 files changed, 42 insertions, 0 deletions
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); +} |
