aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-05-17 10:43:08 +0100
committerGitHub <noreply@github.com>2024-05-17 10:43:08 +0100
commit2de4c40920246e5f27a85e3d577e57a086d40cb7 (patch)
treec61a901cf4064c4c30702d5601a2f4f140934287
parent8645122581391f324b1b81b19308740fdfed2b62 (diff)
parent3c9fb3124eabffea507541223c84f4e5fc26659e (diff)
downloadperlweeklychallenge-club-2de4c40920246e5f27a85e3d577e57a086d40cb7.tar.gz
perlweeklychallenge-club-2de4c40920246e5f27a85e3d577e57a086d40cb7.tar.bz2
perlweeklychallenge-club-2de4c40920246e5f27a85e3d577e57a086d40cb7.zip
Merge pull request #10107 from robbie-hatley/rh269
Got rid of temporary in 269-2.
-rwxr-xr-xchallenge-269/robbie-hatley/perl/ch-2.pl26
1 files changed, 13 insertions, 13 deletions
diff --git a/challenge-269/robbie-hatley/perl/ch-2.pl b/challenge-269/robbie-hatley/perl/ch-2.pl
index 437808c313..2bd708b101 100755
--- a/challenge-269/robbie-hatley/perl/ch-2.pl
+++ b/challenge-269/robbie-hatley/perl/ch-2.pl
@@ -25,17 +25,17 @@ Write a script to distribute the elements as described below:
4) Once @ints is empty, return the concatenated arrays
(@arr1, @arr2).
-Example 1
-Input: @ints = (2, 1, 3, 4, 5)
-Expected output: (2, 3, 4, 5, 1)
+Example 1:
+Input: (2, 1, 3, 4, 5)
+Output: (2, 3, 4, 5, 1)
-Example 2
-Input: @ints = (3, 2, 4)
-Expected output: (3, 4, 2)
+Example 2:
+Input: (3, 2, 4)
+Output: (3, 4, 2)
-Example 3
-Input: @ints = (5, 4, 3 ,8)
-Expected output: (5, 3, 4, 8)
+Example 3:
+Input: (5, 4, 3 ,8)
+Output: (5, 3, 4, 8)
--------------------------------------------------------------------------------------------------------------
PROBLEM NOTES:
@@ -74,11 +74,11 @@ Output is to STDOUT and will be each input followed by the corresponding output.
my @arr1; push @arr1, shift @ints;
my @arr2; push @arr2, shift @ints;
while (@ints) {
- my $x = shift @ints;
- $arr1[-1] > $arr2[-1] and push @arr1, $x
- or push @arr2, $x;
+ $arr1[-1] > $arr2[-1]
+ and push @arr1, shift @ints
+ or push @arr2, shift @ints;
}
- (@arr1, @arr2);
+ return (@arr1, @arr2);
}
# ------------------------------------------------------------------------------------------------------------