aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-10-16 18:41:51 +0100
committerGitHub <noreply@github.com>2022-10-16 18:41:51 +0100
commita53ec1a5a59cffc31c9fed77896472734deb7493 (patch)
tree013d8f1c946ed5a8b90b420a7364ba631216b671
parent14e51838e56d3cf2ec25541164ae8039aedfd3cd (diff)
parent3bc671918464a1ea70fc6efd56b32923746348c4 (diff)
downloadperlweeklychallenge-club-a53ec1a5a59cffc31c9fed77896472734deb7493.tar.gz
perlweeklychallenge-club-a53ec1a5a59cffc31c9fed77896472734deb7493.tar.bz2
perlweeklychallenge-club-a53ec1a5a59cffc31c9fed77896472734deb7493.zip
Merge pull request #6916 from Solathian/branch-for-challenge-186
Adding file for 186
-rw-r--r--challenge-186/solathian/perl/ch-1.pl38
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-186/solathian/perl/ch-1.pl b/challenge-186/solathian/perl/ch-1.pl
new file mode 100644
index 0000000000..783182ccda
--- /dev/null
+++ b/challenge-186/solathian/perl/ch-1.pl
@@ -0,0 +1,38 @@
+#!usr/bin/perl -w
+use strict;
+use warnings;
+
+use feature ('say', 'signatures');
+no warnings 'experimental';
+
+# Challange 186 - 1 - Zip List
+# You are given two list @a and @b of same size.
+
+# Create a subroutine sub zip(@a, @b) that merge the two list as shown in the example below.
+
+# Input: @a = qw/1 2 3/; @b = qw/a b c/;
+
+# Output: zip(@a, @b) should return qw/1 a 2 b 3 c/;
+# zip(@b, @a) should return qw/a 1 b 2 c 3/;
+
+# my @arr1 = qw/1 2 3/;
+# my @arr2 = qw/a b c/;
+
+# zip(\@arr1, \@arr2);
+# zip(\@arr2, \@arr1);
+
+sub zip($a, $b)
+{
+ my @a = @{$a};
+ my @b = @{$b};
+
+ my @result;
+
+ while(@a > 0) # since both arrays are of the same length I can do this.
+ {
+ push(@result, shift(@a));
+ push(@result, shift(@b));
+ }
+
+ say(join(' ',@result));
+} \ No newline at end of file