aboutsummaryrefslogtreecommitdiff
path: root/challenge-059
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-09 03:26:41 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-09 03:26:41 +0100
commita2292a9824c3545abc160c1b909dec60102fb251 (patch)
tree2bd982bbb88a99a38554e404aaa69e4769f4f917 /challenge-059
parent42497f56acb5263f25c9baf5d3e521242333d6e7 (diff)
downloadperlweeklychallenge-club-a2292a9824c3545abc160c1b909dec60102fb251.tar.gz
perlweeklychallenge-club-a2292a9824c3545abc160c1b909dec60102fb251.tar.bz2
perlweeklychallenge-club-a2292a9824c3545abc160c1b909dec60102fb251.zip
- Added Perl and Raku solutions to Linked List task.
Diffstat (limited to 'challenge-059')
-rw-r--r--challenge-059/mohammad-anwar/perl/ch-1.pl28
-rw-r--r--challenge-059/mohammad-anwar/perl/ch-1a.pl25
-rw-r--r--challenge-059/mohammad-anwar/raku/ch-1.p626
-rw-r--r--challenge-059/mohammad-anwar/raku/ch-1a.p623
4 files changed, 102 insertions, 0 deletions
diff --git a/challenge-059/mohammad-anwar/perl/ch-1.pl b/challenge-059/mohammad-anwar/perl/ch-1.pl
new file mode 100644
index 0000000000..a3cfeed4c4
--- /dev/null
+++ b/challenge-059/mohammad-anwar/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $L = [ 1, 4, 3, 2, 5, 2 ];
+my $K = 3;
+my $O = split_list($L, $K);
+
+print sprintf("Input: [ %s ]\n", join (" -> ", @$L));
+print sprintf("Output: [ %s ]\n", join (" -> ", @$O));
+
+sub split_list {
+ my ($L, $K) = @_;
+
+ my $before = [];
+ my $after = [];
+ foreach my $i (@$L) {
+ if ($i < $K) {
+ push @$before, $i;
+ }
+ else {
+ push @$after, $i;
+ }
+ }
+
+ return [ @$before, @$after ];
+}
diff --git a/challenge-059/mohammad-anwar/perl/ch-1a.pl b/challenge-059/mohammad-anwar/perl/ch-1a.pl
new file mode 100644
index 0000000000..7be98d1233
--- /dev/null
+++ b/challenge-059/mohammad-anwar/perl/ch-1a.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use Test::More;
+use Test::Deep;
+
+is_deeply( split_list([ 1, 4, 3, 2, 5, 2 ], 3), [ 1, 2, 2, 4, 3, 5 ]);
+
+done_testing;
+
+sub split_list {
+ my ($L, $K) = @_;
+
+ my $before = [];
+ my $after = [];
+ foreach my $i (@$L) {
+ if ($i < $K) {
+ push @$before, $i;
+ }
+ else {
+ push @$after, $i;
+ }
+ }
+
+ return [ @$before, @$after ];
+}
diff --git a/challenge-059/mohammad-anwar/raku/ch-1.p6 b/challenge-059/mohammad-anwar/raku/ch-1.p6
new file mode 100644
index 0000000000..77b6ade26e
--- /dev/null
+++ b/challenge-059/mohammad-anwar/raku/ch-1.p6
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl6
+
+use v6.d;
+
+sub MAIN($L = [ 1, 4, 3, 2, 5, 2 ], $K = 3) {
+
+ my $O = split-list($L, $K);
+ say sprintf("Input: [ %s ]", $L.join(" -> "));
+ say sprintf("Output: [ %s ]", $O.join(" -> "));
+}
+
+sub split-list($L, $K) {
+
+ my $before = [];
+ my $after = [];
+ for |$L -> $i {
+ if $i < $K {
+ $before.push: $i;
+ }
+ else {
+ $after.push: $i;
+ }
+ }
+
+ return [ |$before, |$after ];
+}
diff --git a/challenge-059/mohammad-anwar/raku/ch-1a.p6 b/challenge-059/mohammad-anwar/raku/ch-1a.p6
new file mode 100644
index 0000000000..ae19e9e834
--- /dev/null
+++ b/challenge-059/mohammad-anwar/raku/ch-1a.p6
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl6
+
+use Test;
+
+is-deeply split-list([ 1, 4, 3, 2, 5, 2 ], 3), [ 1, 2, 2, 4, 3, 5 ];
+
+done-testing;
+
+sub split-list($L, $K) {
+
+ my $before = [];
+ my $after = [];
+ for |$L -> $i {
+ if $i < $K {
+ $before.push: $i;
+ }
+ else {
+ $after.push: $i;
+ }
+ }
+
+ return [ |$before, |$after ];
+}