aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-07-27 23:51:44 +0100
committerGitHub <noreply@github.com>2020-07-27 23:51:44 +0100
commitdda8f08da67f3275923476b73f38f133d96a870b (patch)
treecdd745ad80cac6a5418b0ebd4e2eafc2c1c520db
parent1addedef2af4a49ad1b001ba544276d79606e313 (diff)
parent4abde605fc32a8b47ff8777062b2096ca8035b63 (diff)
downloadperlweeklychallenge-club-dda8f08da67f3275923476b73f38f133d96a870b.tar.gz
perlweeklychallenge-club-dda8f08da67f3275923476b73f38f133d96a870b.tar.bz2
perlweeklychallenge-club-dda8f08da67f3275923476b73f38f133d96a870b.zip
Merge pull request #1989 from fluca1978/pwc71
Pwc71
-rw-r--r--challenge-071/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-071/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-071/luca-ferrari/raku/ch-1.p625
-rw-r--r--challenge-071/luca-ferrari/raku/ch-2.p681
4 files changed, 108 insertions, 0 deletions
diff --git a/challenge-071/luca-ferrari/blog-1.txt b/challenge-071/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..cc472f9865
--- /dev/null
+++ b/challenge-071/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/07/27/PerlWeeklyChallenge71.html#task1
diff --git a/challenge-071/luca-ferrari/blog-2.txt b/challenge-071/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..13ca6e0765
--- /dev/null
+++ b/challenge-071/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/07/27/PerlWeeklyChallenge71.html#task2
diff --git a/challenge-071/luca-ferrari/raku/ch-1.p6 b/challenge-071/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..48f0e1e993
--- /dev/null
+++ b/challenge-071/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,25 @@
+#!raku
+
+
+sub MAIN( Int $N where { $N > 1 } ) {
+ my @array;
+ my @peak;
+
+ while ( @array.elems < $N ) {
+ my $random = ( 1 .. 50 ).rand.Int;
+ @array.push: $random if ( ! @array.grep( * ~~ $random ) );
+ }
+
+
+ for 0 ..^ @array.elems {
+ my $neighbour-left = $_ == 0 ?? Nil !! @array[ $_ - 1 ];
+ my $neighbour-right = $_ == ( @array.elems - 1 ) ?? Nil !! @array[ $_ + 1 ];
+ my $current = @array[ $_ ];
+
+ @peak.push: $current if ( $neighbour-left && $current > $neighbour-left )
+ || ( $neighbour-right && $current > $neighbour-right );
+ }
+
+ "Array: { @array }".say;
+ "Peak: { @peak }".say;
+}
diff --git a/challenge-071/luca-ferrari/raku/ch-2.p6 b/challenge-071/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..947f83a1ca
--- /dev/null
+++ b/challenge-071/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,81 @@
+#!raku
+
+
+class Node {
+ has $.value;
+ has $.next is rw;
+
+
+ method Str() {
+ my $current = self;
+ my $string;
+ while ( $current ) {
+ $string ~= "{ $current.value }";
+ $string ~= " -> " if $current.next;
+ $current = $current.next;
+ }
+
+ $string;
+ }
+
+
+ method size() {
+ my $size-of-the-list = 0;
+ my $current = self;
+ while ( $current ) {
+ $size-of-the-list++;
+ $current = $current.next;
+ }
+
+ $size-of-the-list;
+ }
+}
+
+sub MAIN( Int $N where { $N > 0 }, *@list ) {
+ say @list;
+
+ # build the list backward and keep the root
+ # at the list
+ my $head = Nil;
+ my $current = Nil;
+ loop ( my $i = @list.elems - 1; $i >= 0; $i-- ) {
+ $head = Node.new( value => @list[ $i ],
+ next => $head );
+ }
+
+ # compute the size of the list
+ my $size-of-the-list = $head.size;
+ "Size of the list is $size-of-the-list".say;
+ $head.put;
+
+
+
+
+
+ my $index = 1;
+ my $index-to-remove = $size-of-the-list - $N + 1;
+
+
+ # particular case: remove the root
+ $head = $head.next if ( $index == $index-to-remove || $N > $size-of-the-list );
+
+ # remove a specific element, but only if this has not been already done
+ # by removing the root element and thus changing the size of the list
+ if ( $head.size == $size-of-the-list ) {
+ $current = $head;
+ while ( $current ) {
+ if ( ( $index + 1 ) == ( $size-of-the-list - $N + 1 ) ) {
+ $current.next = $current.next.next;
+ last;
+ }
+
+ $index++;
+ $current = $current.next;
+ }
+ }
+
+
+ # print the modified list
+ $head.put;
+
+}