aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-11 22:18:29 +0100
committerGitHub <noreply@github.com>2019-10-11 22:18:29 +0100
commiteeeada1bbb3f13f765e723f0cb647f8e8e0541f4 (patch)
treea240538eda370406f4304c7bed6ed36975a8369a
parent07552f965ae27ff537c6b3ff4084eca21807a3b4 (diff)
parent39249ff15282d6d8896f287e55e0480f50591748 (diff)
downloadperlweeklychallenge-club-eeeada1bbb3f13f765e723f0cb647f8e8e0541f4.tar.gz
perlweeklychallenge-club-eeeada1bbb3f13f765e723f0cb647f8e8e0541f4.tar.bz2
perlweeklychallenge-club-eeeada1bbb3f13f765e723f0cb647f8e8e0541f4.zip
Merge pull request #743 from Doomtrain14/master
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
-rw-r--r--challenge-029/yet-ebreo/perl5/ch-1.pl2
-rw-r--r--challenge-029/yet-ebreo/perl5/ch-2.pl4
-rw-r--r--challenge-029/yet-ebreo/perl6/ch-1.p643
-rw-r--r--challenge-029/yet-ebreo/perl6/ch-2.p636
-rw-r--r--challenge-029/yet-ebreo/perl6/fib.sobin0 -> 48344 bytes
5 files changed, 83 insertions, 2 deletions
diff --git a/challenge-029/yet-ebreo/perl5/ch-1.pl b/challenge-029/yet-ebreo/perl5/ch-1.pl
index a0392cc0d0..46d8fc7865 100644
--- a/challenge-029/yet-ebreo/perl5/ch-1.pl
+++ b/challenge-029/yet-ebreo/perl5/ch-1.pl
@@ -36,7 +36,7 @@ sub expand {
my ($l,$m,$r) = ($`,$1,$');
# The captured value stored in $m was split using comma(,) as delimiter
# The resulting list was used in a for loop
- for (split ",", $m) {
+ for (",$m"=~/,([^,]*)/g) {
#A new string containing the prematch, a value from the split operation of $m
#and the postmatch will be used in the recursive function.
#The process will be repeated until...
diff --git a/challenge-029/yet-ebreo/perl5/ch-2.pl b/challenge-029/yet-ebreo/perl5/ch-2.pl
index fbb28cf5d8..4c8b959c50 100644
--- a/challenge-029/yet-ebreo/perl5/ch-2.pl
+++ b/challenge-029/yet-ebreo/perl5/ch-2.pl
@@ -1,4 +1,6 @@
-
+#!/usr/bin/env perl
+# Write a script to demonstrate calling a C function.
+# It could be any user defined or standard C function.
use strict;
use warnings;
use feature 'say';
diff --git a/challenge-029/yet-ebreo/perl6/ch-1.p6 b/challenge-029/yet-ebreo/perl6/ch-1.p6
new file mode 100644
index 0000000000..71d2c26c6a
--- /dev/null
+++ b/challenge-029/yet-ebreo/perl6/ch-1.p6
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+# Write a script to demonstrate brace expansion.
+# For example, script would take command line argument
+# Perl {Daily,Weekly,Monthly,Yearly} Challenge and should expand it and print like below:
+# Perl Daily Challenge
+# Perl Weekly Challenge
+# Perl Monthly Challenge
+# Perl Yearly Challenge
+
+sub MAIN (
+ $string #= String containing braces "{}" to expand
+) {
+ my $mstring = $string;
+ $mstring~~s:g/\{\}//;
+ expand($mstring);
+}
+
+sub expand ($string) {
+ #The string will be stored in $string
+ my $mstring = $string;
+
+ #- Regex was used to check if the string contains matching braces
+ #- Notice that [^{}]* instead of a simple .* to match the contents of the braces
+ # this is to make sure that the inner most brace is processed first
+ #- The matching string was captured using () and will be stored in $1
+ if ($mstring ~~ /\{(<-[{}]>*)\}/) {
+ # The captured value, the prematch and postmatch were stored
+ # in variables $l,$m and $r respectively
+ my ($l,$m,$r) = ($/.prematch,$0,$/.postmatch);
+ # The captured value stored in $m was split using comma(,) as delimiter
+ # The resulting list was used in a for loop
+ for ($m.split(",")) {
+ #A new string containing the prematch, a value from the split operation of $m
+ #and the postmatch will be used in the recursive function.
+ #The process will be repeated until...
+ expand($l~$_~$r);
+ }
+ } else {
+ #The string does not have matching braces.
+ #Then final string will be printed
+ say $mstring;
+ }
+} \ No newline at end of file
diff --git a/challenge-029/yet-ebreo/perl6/ch-2.p6 b/challenge-029/yet-ebreo/perl6/ch-2.p6
new file mode 100644
index 0000000000..867c17daa2
--- /dev/null
+++ b/challenge-029/yet-ebreo/perl6/ch-2.p6
@@ -0,0 +1,36 @@
+use NativeCall;
+use experimental :cached;
+sub fib(int32) returns int32 is native('fib.so') {*}
+
+sub MAIN () {
+
+ my $start = now;
+ print (perl_fib($_)~" ") for 1..36;
+
+ say "\nRun Time (Perl): "~(now - $start)~" sec\n";
+
+ $start = now;
+ print (perl_fib_cached($_)~" ") for 1..36;
+
+ say "\nRun Time (Perl-Cached): "~(now - $start)~" sec\n";
+
+ $start = now;
+ print (fib($_)~" ") for 1..36;
+
+ say "\nRun Time: (NativeCall)"~(now - $start)~" sec\n";
+}
+
+sub perl_fib($n) { ($n == 0) ?? 0 !! ($n == 1) ?? 1 !! perl_fib($n-1)+perl_fib($n-2) }
+sub perl_fib_cached($n) is cached { ($n == 0) ?? 0 !! ($n == 1) ?? 1 !! perl_fib_cached($n-1)+perl_fib_cached($n-2) }
+
+
+# perl6 .\ch-2.p6 32
+# 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352
+# Run Time (Perl): 74.794843 sec
+#
+# 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352
+# Run Time (Perl-Cached): 0.029755 sec
+#
+# 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352
+# Run Time: (NativeCall)0.31090124 sec
+
diff --git a/challenge-029/yet-ebreo/perl6/fib.so b/challenge-029/yet-ebreo/perl6/fib.so
new file mode 100644
index 0000000000..95cef59a3c
--- /dev/null
+++ b/challenge-029/yet-ebreo/perl6/fib.so
Binary files differ