aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Thompson <i@ry.ca>2019-12-23 05:00:31 -0600
committerRyan Thompson <i@ry.ca>2019-12-23 05:00:31 -0600
commitdf7b25866f33658cf8d56dc6d2145b11e12af445 (patch)
treee5d7c54e656722636c7db2bf4ef8c270fd1d1485
parentb01bda291bbee2124e48405822e75808cbd431c3 (diff)
downloadperlweeklychallenge-club-df7b25866f33658cf8d56dc6d2145b11e12af445.tar.gz
perlweeklychallenge-club-df7b25866f33658cf8d56dc6d2145b11e12af445.tar.bz2
perlweeklychallenge-club-df7b25866f33658cf8d56dc6d2145b11e12af445.zip
40.1 solutions
-rw-r--r--challenge-040/ryan-thompson/blog.txt1
-rwxr-xr-xchallenge-040/ryan-thompson/perl5/ch-1.pl44
-rw-r--r--challenge-040/ryan-thompson/perl6/ch-1.p615
3 files changed, 60 insertions, 0 deletions
diff --git a/challenge-040/ryan-thompson/blog.txt b/challenge-040/ryan-thompson/blog.txt
new file mode 100644
index 0000000000..8ef851df59
--- /dev/null
+++ b/challenge-040/ryan-thompson/blog.txt
@@ -0,0 +1 @@
+http://www.ry.ca/2019/12/zip6/
diff --git a/challenge-040/ryan-thompson/perl5/ch-1.pl b/challenge-040/ryan-thompson/perl5/ch-1.pl
new file mode 100755
index 0000000000..c24136e738
--- /dev/null
+++ b/challenge-040/ryan-thompson/perl5/ch-1.pl
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+#
+# ch-1.pl - zip6
+#
+# Ryan Thompson <rjt@cpan.org>
+
+use 5.010;
+use warnings;
+use strict;
+use Carp;
+use List::Util qw< max any >;
+no warnings 'uninitialized';
+
+sub my_zip6(\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@);
+sub zip6ref($$;@);
+sub zip6ref_check($$;@);
+
+my @a1 = qw<I L O V E Y O U>;
+my @a2 = qw<2 4 0 3 2 0 1 9>;
+my @a3 = qw<! ? X $ % ^ & *>;
+
+say join ' ', @$_ for my_zip6 @a1, @a2, @a3;
+
+# Here's one solution, trying to match List::MoreUtils' behaviour
+sub my_zip6(\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) {
+ my $max = max map $#$_, @_; # Use the size of the longest array
+
+ map { my $i = $_; [ map $_->[$i], @_ ] } 0..$max;
+}
+
+# And now the same code, with a different prototype, which is more flexible
+sub zip6ref($$;@) {
+ my $max = max map $#$_, @_; # Use the size of the longest array
+
+ map { my $i = $_; [ map $_->[$i], @_ ] } 0..$max;
+}
+
+# As above, but with a check to ensure all args are ARRAY refs. Slower.
+sub zip6ref_check($$;@) {
+ croak "Not an ARRAY ref" if any { 'ARRAY' ne ref } @_;
+ my $max = max map $#$_, @_; # Use the size of the longest array
+
+ map { my $i = $_; [ map $_->[$i], @_ ] } 0..$max;
+}
diff --git a/challenge-040/ryan-thompson/perl6/ch-1.p6 b/challenge-040/ryan-thompson/perl6/ch-1.p6
new file mode 100644
index 0000000000..d323d5a6c6
--- /dev/null
+++ b/challenge-040/ryan-thompson/perl6/ch-1.p6
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl6
+
+# ch-1.p6 - zip6
+#
+# Ryan Thompson <rjt@cpan.org>
+
+my @a1 = 'ILOVEYOU'.comb;
+my @a2 = '24032019'.comb;
+my @a3 = '!?X$%^&*'.comb;
+
+# The zip routine, much like Perl 5's List::Utils:
+.Str.say for zip @a1, @a2, @a3;
+
+# Or Raku's new chaining infix Z(ip) operator:
+.Str.say for @a1 Z @a2 Z @a3;