aboutsummaryrefslogtreecommitdiff
path: root/challenge-001
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-03-31 21:09:34 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-03-31 21:09:34 +0100
commit7297cfb9db4bc3b6b72bf69a7bab67a06e8f935a (patch)
tree6fac3f880f7a5847f9198935107a6d61337759d2 /challenge-001
parent07f2fc91840ac12146fdde51ea5a42447a88edfe (diff)
downloadperlweeklychallenge-club-7297cfb9db4bc3b6b72bf69a7bab67a06e8f935a.tar.gz
perlweeklychallenge-club-7297cfb9db4bc3b6b72bf69a7bab67a06e8f935a.tar.bz2
perlweeklychallenge-club-7297cfb9db4bc3b6b72bf69a7bab67a06e8f935a.zip
- Added solutions from Althanasius and Mark Senn.
Diffstat (limited to 'challenge-001')
-rw-r--r--challenge-001/althanasius/perl5/ch-1.sh4
-rw-r--r--challenge-001/althanasius/perl5/ch-2.sh13
-rw-r--r--challenge-001/mark-senn/perl6/ch-1.p621
-rw-r--r--challenge-001/mark-senn/perl6/ch-2.p666
4 files changed, 104 insertions, 0 deletions
diff --git a/challenge-001/althanasius/perl5/ch-1.sh b/challenge-001/althanasius/perl5/ch-1.sh
new file mode 100644
index 0000000000..257c5931b4
--- /dev/null
+++ b/challenge-001/althanasius/perl5/ch-1.sh
@@ -0,0 +1,4 @@
+perl -wE "my $s = 'Perl Weekly Challenge'; my $c = $s =~ tr/e/E/;
+say qq[$s: $c];"
+
+#syntax error at -e line 1, near "my ="
diff --git a/challenge-001/althanasius/perl5/ch-2.sh b/challenge-001/althanasius/perl5/ch-2.sh
new file mode 100644
index 0000000000..0759b63576
--- /dev/null
+++ b/challenge-001/althanasius/perl5/ch-2.sh
@@ -0,0 +1,13 @@
+perl -wE "for (1 .. 20) { $p = 0; $q = 0; if (!($_ % 3)) { print
+'fizz'; ++$p } if (!($_ % 5)) { say 'buzz'; ++$q; } say '' if $p && !$q;
+say $_ if !$p && !$q; }"
+
+#syntax error at -e line 1, near "{ ="
+#Unknown regexp modifier "/h" at -e line 1, at end of line
+#syntax error at -e line 2, near "++ }"
+#Unknown regexp modifier "/h" at -e line 2, at end of line
+#syntax error at -e line 2, near "++;"
+#syntax error at -e line 2, near "if &&"
+#Unknown regexp modifier "/h" at -e line 3, at end of line
+#syntax error at -e line 3, near "! &&"
+#Execution of -e aborted due to compilation errors.
diff --git a/challenge-001/mark-senn/perl6/ch-1.p6 b/challenge-001/mark-senn/perl6/ch-1.p6
new file mode 100644
index 0000000000..8691a49fde
--- /dev/null
+++ b/challenge-001/mark-senn/perl6/ch-1.p6
@@ -0,0 +1,21 @@
+#
+# Retrieved from
+# https://perlweeklychallenge.org/blog/a-new-week-a-new-challenge
+# on 2019-03-27 at 11:28 -04:
+#
+# 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.
+#
+
+$_ = 'Perl Weekly Challenge';
+
+# See
+# https://docs.perl6.org/syntax/tr$SOLIDUS$SOLIDUS$SOLIDUS
+# and
+# https://docs.perl6.org/type/StrDistance
+# for more information about "tr///" and the "StrDistance" object.
+my $distance = tr/e/E/;
+say +$distance; \ No newline at end of file
diff --git a/challenge-001/mark-senn/perl6/ch-2.p6 b/challenge-001/mark-senn/perl6/ch-2.p6
new file mode 100644
index 0000000000..057621e9e8
--- /dev/null
+++ b/challenge-001/mark-senn/perl6/ch-2.p6
@@ -0,0 +1,66 @@
+#
+# Retrieved from
+# https://perlweeklychallenge.org/blog/a-new-week-a-new-challenge
+# on 2019-03-27 at 11:28 -04:
+#
+# 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.
+#
+# Since we are not playing Perl Golf I'm going to concentrate on making
+# the code understandable.
+#
+# The
+# Numbers divisible by both become fizz buzz.
+# condition would make this a complicated structure of if statements. It
+# might be easier for people to understand if a
+# (conndition) and print "...";
+# construct was used instead. This will make it easier to add conditions
+# like if divisible by 3, 5, and 7 print "fizz buzz baz". "If" statements
+# are hard enough to read when formatted in two dimensions---they're
+# even worse when typeset in one dimension. (I am assuming the one-liner
+# must be one physical line---not one logical line.)
+#
+# We could use
+# perl6 -e '(1..20).map({ my $t=""; my $e3 = $_ %% 3; my $e5 = $_ %% 5; $e3 and $t~="fizz"; $e3 && $e5 and $t~=" "; $e5 and $t~="buzz"; !$e3 && !$e5 and $t~=$_; say $t;})'
+#
+# Using "for" instead of "map" will be understood by people that don't
+# already know about "map" and the "{...}" needed inside of it. Put
+# two spaces around each statement in the for body to make it easier to read.
+# perl6 -e 'for (1..20) { my $t=""; my $e3 = $_ %% 3; my $e5 = $_ %% 5; $e3 and $t~="fizz"; $e3 && $e5 and $t~=" "; $e5 and $t~="buzz"; !$e3 && !$e5 and $t~=$_; say $t;}'
+#
+# Instead of building the string in $t and printing it at the end of
+# the loop we can make this more clear by doing print statements as we go.
+# For uniformity use only "print" instead of a combination of "print" and
+# "say". Multi-line commented version:
+# for (1..20)
+# {
+# # Is $_ evenly divisible by 3?
+# my $e3 = $_ %% 3;
+# # Is $_ evenly divisible by 5?
+# my $e5 = $_ %% 5;
+# $e3 and print "fizz";
+# $e3 && $e5 and print " ";
+# $e5 and print "buzz";
+# !$e3 && !$e5 and print $_;
+# print "\n";
+# }
+#
+
+perl6 -e 'for (1..20) { my $e3 = $_ %% 3; my $e5 = $_ %% 5; $e3 and print "fizz"; $e3 && $e5 and print " "; $e5 and print "buzz"; !$e3 && !$e5 and print $_; print "\n"; }'
+
+#===SORRY!=== Error while compiling /home/manwar/github/perlweeklychallenge-club/challenge-001/mark-senn/perl6/ch-2.p6
+#Two terms in a row
+#at /home/manwar/github/perlweeklychallenge-club/challenge-001/mark-senn/perl6/ch-2.p6:53
+#------> perl6 -e⏏ 'for (1..20) { my $e3 = $_ %% 3; my $
+# expecting any of:
+# infix
+# infix stopper
+# postfix
+# statement end
+# statement modifier
+# statement modifier loop
+