From b213013759f49650d5b2e57238a66d36b8400b70 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 3 Apr 2019 19:37:45 +0100 Subject: - Added solution by "Adam Russell" 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 (limited to 'challenge-001') 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..fc34504e9d --- /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..6d8719ed05 --- /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 From d579e514f4f37a998fb5efc74286b0cf413ad491 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 3 Apr 2019 20:02:51 +0100 Subject: - Added solution by "James A Smith" for challenge 001. --- challenge-001/james-smith/README | 1 + challenge-001/james-smith/perl5/ch-1.sh | 1 + challenge-001/james-smith/perl5/ch-2.sh | 1 + challenge-001/james-smith/perl6/ch-1.sh | 1 + challenge-001/james-smith/perl6/ch-2.p6 | 3 +++ 5 files changed, 7 insertions(+) create mode 100644 challenge-001/james-smith/README create mode 100644 challenge-001/james-smith/perl5/ch-1.sh create mode 100644 challenge-001/james-smith/perl5/ch-2.sh create mode 100644 challenge-001/james-smith/perl6/ch-1.sh create mode 100644 challenge-001/james-smith/perl6/ch-2.p6 (limited to 'challenge-001') diff --git a/challenge-001/james-smith/README b/challenge-001/james-smith/README new file mode 100644 index 0000000000..573d9eb02a --- /dev/null +++ b/challenge-001/james-smith/README @@ -0,0 +1 @@ +Solution by James Smith diff --git a/challenge-001/james-smith/perl5/ch-1.sh b/challenge-001/james-smith/perl5/ch-1.sh new file mode 100644 index 0000000000..70435d35ec --- /dev/null +++ b/challenge-001/james-smith/perl5/ch-1.sh @@ -0,0 +1 @@ +perl -E 'say my $n = (my $s = "Perl Weekly Challenge" )=~ y/e/E/; say $s;' diff --git a/challenge-001/james-smith/perl5/ch-2.sh b/challenge-001/james-smith/perl5/ch-2.sh new file mode 100644 index 0000000000..1e375cd941 --- /dev/null +++ b/challenge-001/james-smith/perl5/ch-2.sh @@ -0,0 +1 @@ +perl -E 'say "".($_%3?"":"Fizz").($_%5?"":"Buzz")||$_ for 1..20;' diff --git a/challenge-001/james-smith/perl6/ch-1.sh b/challenge-001/james-smith/perl6/ch-1.sh new file mode 100644 index 0000000000..c4ef1e4e0a --- /dev/null +++ b/challenge-001/james-smith/perl6/ch-1.sh @@ -0,0 +1 @@ +perl6 -e 'say m/^0*(\d+[.\d+]?)/??"$0"!!$_ for @*ARGS' 121 0.012 -012 002 000 diff --git a/challenge-001/james-smith/perl6/ch-2.p6 b/challenge-001/james-smith/perl6/ch-2.p6 new file mode 100644 index 0000000000..80d37995c2 --- /dev/null +++ b/challenge-001/james-smith/perl6/ch-2.p6 @@ -0,0 +1,3 @@ +sub mp($n) {chr $n+($n < 10??48!!55)} +sub b35($n) {$n??b35(floor $n/35)~mp($n%35)!!''} +say b35 $_ for @*ARGS; -- cgit From 8f2a9c584fd921037ccfb8ec304865dae2d52796 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 3 Apr 2019 20:17:55 +0100 Subject: - Added solution by "James A Smith" for challenge 002. --- challenge-001/james-smith/perl6/ch-1.sh | 1 - challenge-001/james-smith/perl6/ch-2.p6 | 3 --- 2 files changed, 4 deletions(-) delete mode 100644 challenge-001/james-smith/perl6/ch-1.sh delete mode 100644 challenge-001/james-smith/perl6/ch-2.p6 (limited to 'challenge-001') diff --git a/challenge-001/james-smith/perl6/ch-1.sh b/challenge-001/james-smith/perl6/ch-1.sh deleted file mode 100644 index c4ef1e4e0a..0000000000 --- a/challenge-001/james-smith/perl6/ch-1.sh +++ /dev/null @@ -1 +0,0 @@ -perl6 -e 'say m/^0*(\d+[.\d+]?)/??"$0"!!$_ for @*ARGS' 121 0.012 -012 002 000 diff --git a/challenge-001/james-smith/perl6/ch-2.p6 b/challenge-001/james-smith/perl6/ch-2.p6 deleted file mode 100644 index 80d37995c2..0000000000 --- a/challenge-001/james-smith/perl6/ch-2.p6 +++ /dev/null @@ -1,3 +0,0 @@ -sub mp($n) {chr $n+($n < 10??48!!55)} -sub b35($n) {$n??b35(floor $n/35)~mp($n%35)!!''} -say b35 $_ for @*ARGS; -- cgit