diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-09-21 01:06:25 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-09-21 01:06:25 +0100 |
| commit | c495343d52dae9415a6ea527beaf33bbed923bad (patch) | |
| tree | 539979b30766053c9e42ad8f770b086b449dd022 | |
| parent | 57cdc88f2c0481d83653ff79a53733ce3174d805 (diff) | |
| download | perlweeklychallenge-club-c495343d52dae9415a6ea527beaf33bbed923bad.tar.gz perlweeklychallenge-club-c495343d52dae9415a6ea527beaf33bbed923bad.tar.bz2 perlweeklychallenge-club-c495343d52dae9415a6ea527beaf33bbed923bad.zip | |
- Added solutions by Colin Crain.
| -rw-r--r-- | challenge-078/colin-crain/perl/ch-1.pl | 64 | ||||
| -rw-r--r-- | challenge-078/colin-crain/perl/ch-2.pl | 119 | ||||
| -rw-r--r-- | challenge-078/colin-crain/raku/ch-1.raku | 51 | ||||
| -rw-r--r-- | challenge-078/colin-crain/raku/ch-2.raku | 103 | ||||
| -rw-r--r-- | stats/pwc-current.json | 654 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 68 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 1120 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 766 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 40 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 96 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 114 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 62 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 98 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 102 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 88 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 46 |
16 files changed, 1968 insertions, 1623 deletions
diff --git a/challenge-078/colin-crain/perl/ch-1.pl b/challenge-078/colin-crain/perl/ch-1.pl new file mode 100644 index 0000000000..a36ff8652d --- /dev/null +++ b/challenge-078/colin-crain/perl/ch-1.pl @@ -0,0 +1,64 @@ +#! /opt/local/bin/perl +# +# follow_the_leader.pl +# +# TASK #1 › Leader Element +# Submitted by: Mohammad S Anwar +# You are given an array @A containing distinct integers. +# +# Write a script to find all leader elements in the array @A. Print (0) +# if none found. +# +# An element is leader if it is greater than all the elements to its +# right side. +# +# Example 1: +# Input: @A = (9, 10, 7, 5, 6, 1) +# Output: (10, 7, 6, 1) +# Example 2: +# Input: @A = (3, 4, 5) +# Output: (5) +# +# method: +# working from the end, the tail element is by definition the +# "leader" of none. From there a running local maximum is +# established among elements already seen and the focus moves one +# element to the left. If the element is greater than the local +# maximum, it is the leader and becomes the new maximum. It is also +# unshifted onto the front of the output array. +# +# +# 2020 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +use warnings; +use strict; +use feature ":5.26"; + +## ## ## ## ## MAIN: + +my @input = @ARGV; +@input = (9, 10, 7, 5, 6, 1) if scalar @ARGV == 0; +say "input: (", (join ', ', @input), ")"; + + +my @output = my ($max) = (pop @input); + +while (@input) { + my $ele = pop @input; + if ($ele > $max) { + $max = $ele; + unshift @output, $ele; + } +} +say "output: (", (join ', ', @output), ")"; + + + + + + + +## ## ## ## ## SUBS: diff --git a/challenge-078/colin-crain/perl/ch-2.pl b/challenge-078/colin-crain/perl/ch-2.pl new file mode 100644 index 0000000000..cd07ef3383 --- /dev/null +++ b/challenge-078/colin-crain/perl/ch-2.pl @@ -0,0 +1,119 @@ +#! /opt/local/bin/perl +# +# swing_to_the_left.pl +# +# TASK #2 › Left Rotation +# Submitted by: Mohammad S Anwar +# You are given array @A containing positive numbers and @B containing +# one or more indices from the array @A. +# +# Write a script to left rotate @A so that the number at the first index +# of @B becomes the first element in the array. Similary, left rotate @A +# again so that the number at the second index of @B becomes the first +# element in the array. +# +# Example 1: +# Input: +# @A = (10 20 30 40 50) +# @B = (3 4) +# +# Explanation: +# a) We left rotate the 3rd index element (40) in the @A to make it 0th +# index member in the array. +# [40 50 10 20 30] +# +# b) We left rotate the 4th index element (50) in the @A to make it 0th +# index member in the array. +# [50 10 20 30 40] +# +# Output: +# [40 50 10 20 30] +# [50 10 20 30 40] +# +# Example 2: +# +# Input: +# @A = (7 4 2 6 3) +# @B = (1 3 4) +# +# Explanation: +# a) We left rotate the 1st index element (4) in the @A to make it +# 0th index member in the array. +# [4 2 6 3 7] +# +# b) We left rotate the 3rd index element (6) in the @A to make it +# 0th index member in the array. +# [6 3 7 4 2] +# +# c) We left rotate the 4th index element (3) in the @A to make it +# 0th index member in the array. +# [3 7 4 2 6] +# +# Output: +# [4 2 6 3 7] +# [6 3 7 5 2] +# [3 7 4 2 6] + +# ---------------------------------------- +# +# method: +# I'm not sure "rotate" is exactly the right word for whats being +# asked for here, but rather what we are being asked to do is to +# produce the output as though the array had been rotated. The +# distinction is important as we need to retain the integrety of the +# original array and perform multiple transformations for output, as +# the transformations are not consecutivly applied in a churning +# fashion, but rather different applications to the atarting +# sequence. +# +# The new sequences rearrange the elements such that the the tail of +# the array, starting at the indicated element, becomes the head, +# and the head, up to the break, becomes the tail. This can be done +# easily with array slices. +# +# As removing the head element and placing it on the end is the act +# of a left rotation, this is the same action moving a block of +# elements simultaniously rather than individual elements +# sequentially. In this sense it satisfies both the function and the +# spirit of the challenge. +# +# +# +# 2020 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +use warnings; +use strict; +use feature ":5.26"; + +## ## ## ## ## MAIN: + + +my @array = (7, 4, 2, 6, 3); +my @idxs = (1, 3, 0, 4); +my @output; +my $end = scalar @array - 1; + +for my $idx (@idxs) { + $idx == 0 and do {(push @output, \@array); next}; + my @shifted = @array[$idx..$end, 0..$idx-1]; + push @output, \@shifted ; +} + +say "array: (", (join ', ', @array), ")"; +say "index list: (", (join ', ', @idxs ), ")\n"; + +say "[", (join ' ', $_->@*), "]" for @output; + + + + + + + + + + +## ## ## ## ## SUBS: diff --git a/challenge-078/colin-crain/raku/ch-1.raku b/challenge-078/colin-crain/raku/ch-1.raku new file mode 100644 index 0000000000..e528ed3e06 --- /dev/null +++ b/challenge-078/colin-crain/raku/ch-1.raku @@ -0,0 +1,51 @@ +#!/usr/bin/env perl6 +# +# +# follow-the-leader.raku +# +# TASK #1 › Leader Element +# Submitted by: Mohammad S Anwar +# You are given an array @A containing distinct integers. +# +# Write a script to find all leader elements in the array @A. Print (0) +# if none found. +# +# An element is leader if it is greater than all the elements to its +# right side. +# +# Example 1: +# Input: @A = (9, 10, 7, 5, 6, 1) +# Output: (10, 7, 6, 1) +# Example 2: +# Input: @A = (3, 4, 5) +# Output: (5) +# +# method: working from the end, the tail element is by definition the +# "leader" of none. From there a running local maximum is +# established among elements already seen and the focus moves one +# element to the left. If the element is greater than the local +# maximum, it is the leader and becomes the new maximum. Leaders are +# propgated to the output array, which needs to be revered back to +# +# +# 2020 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +unit sub MAIN (*@input) ; + +## in +@input.elems == 0 and @input = 9, 10, 7, 5, 6, 1; + +## work +my $max = -Inf; +my @output = @input.reverse + .map( { $_ > $max ?? ($max = $_) !! Nil } ) + .grep( *.defined ); +@output .= reverse; + +## out +say " input: ", @input; +say "output: ", @output; + diff --git a/challenge-078/colin-crain/raku/ch-2.raku b/challenge-078/colin-crain/raku/ch-2.raku new file mode 100644 index 0000000000..c491571918 --- /dev/null +++ b/challenge-078/colin-crain/raku/ch-2.raku @@ -0,0 +1,103 @@ +#!/usr/bin/env perl6 +# +# +# swing_to_the_left.raku +# +# TASK #2 › Left Rotation +# Submitted by: Mohammad S Anwar +# You are given array @A containing positive numbers and @B containing +# one or more indices from the array @A. +# +# Write a script to left rotate @A so that the number at the first index +# of @B becomes the first element in the array. Similary, left rotate @A +# again so that the number at the second index of @B becomes the first +# element in the array. +# +# Example 1: +# Input: +# @A = (10 20 30 40 50) +# @B = (3 4) +# +# Explanation: +# a) We left rotate the 3rd index element (40) in the @A to make it 0th +# index member in the array. +# [40 50 10 20 30] +# +# b) We left rotate the 4th index element (50) in the @A to make it 0th +# index member in the array. +# [50 10 20 30 40] +# +# Output: +# [40 50 10 20 30] +# [50 10 20 30 40] +# +# Example 2: +# +# Input: +# @A = (7 4 2 6 3) +# @B = (1 3 4) +# +# Explanation: +# a) We left rotate the 1st index element (4) in the @A to make it +# 0th index member in the array. +# [4 2 6 3 7] +# +# b) We left rotate the 3rd index element (6) in the @A to make it +# 0th index member in the array. +# [6 3 7 4 2] +# +# c) We left rotate the 4th index element (3) in the @A to make it +# 0th index member in the array. +# [3 7 4 2 6] +# +# Output: +# [4 2 6 3 7] +# [6 3 7 5 2] +# [3 7 4 2 6] +# +# ---------------------------------------- +# +# method: +# I'm not sure "rotate" is exactly the right word for whats being +# asked for here, as rather what we are being asked to do is to +# produce the output as though the array had been rotated. The +# distinction is important as we need to retain the integrity of the +# original array and perform multiple transformations for output, as +# the transformations are not consecutivly applied in a churning +# fashion, but rather different applications to the starting +# sequence. +# +# The new sequences rearrange the elements such that the the tail of +# the array, starting at the indicated element, becomes the head, +# and the head, up to the break, becomes the tail. This can be done +# easily with array slices. +# +# As removing the head element and placing it on the end is the act +# of a left rotation, this is the same action moving a block of +# elements simultaniously rather than individual elements +# sequentially. In this sense it satisfies both the function and the +# spirit of the challenge. +# +# 2020 colin crain +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + + + +unit sub MAIN (Str $arraystr = "7,4,2,6,3", Str $idxstr = "1,3,0,4") ; + +## in +my @array = $arraystr.split(','); +my @idxs = $idxstr.split(','); +my @output; + +## work +for @idxs -> $idx { + $idx == 0 and do { @output.push: @array; next }; + @output.push: @array[|($idx..@array.end), |^$idx]; +} + +## out +say "array: ", @array; +say "index list: ", @idxs; +say "output:\n"; +.say for @output; diff --git a/stats/pwc-current.json b/stats/pwc-current.json index cbcd39d713..a5f076e506 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,20 +1,263 @@ { + "chart" : { + "type" : "column" + }, "title" : { "text" : "Perl Weekly Challenge - 078" }, + "subtitle" : { + "text" : "[Champions: 41] Last updated at 2020-09-21 00:06:10 GMT" + }, + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 + } + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "series" : [ + { + "colorByPoint" : 1, + "name" : "Perl Weekly Challenge - 078", + "data" : [ + { + "drilldown" : "Abigail", + "name" : "Abigail", + "y" : 2 + }, + { + "y" : 3, + "name" : "Adam Russell", + "drilldown" : "Adam Russell" + }, + { + "drilldown" : "Alexander Pankoff", + "name" : "Alexander Pankoff", + "y" : 2 + }, + { + "name" : "Andinus", + "y" : 4, + "drilldown" : "Andinus" + }, + { + "y" : 3, + "name" : "Andrew Shitov", + "drilldown" : "Andrew Shitov" + }, + { + "y" : 2, + "name" : "Anton Fedotov", + "drilldown" : "Anton Fedotov" + }, + { + "y" : 5, + "name" : "Arne Sommer", + "drilldown" : "Arne Sommer" + }, + { + "drilldown" : "Athanasius", + "name" : "Athanasius", + "y" : 4 + }, + { + "y" : 2, + "name" : "Bob Lied", + "drilldown" : "Bob Lied" + }, + { + "drilldown" : "Cheok-Yin Fung", + "y" : 2, + "name" : "Cheok-Yin Fung" + }, + { + "drilldown" : "Colin Crain", + "y" : 5, + "name" : "Colin Crain" + }, + { + "drilldown" : "Dave Cross", + "y" : 2, + "name" : "Dave Cross" + }, + { + "drilldown" : "Dave Jacoby", + "name" : "Dave Jacoby", + "y" : 2 + }, + { + "drilldown" : "E. Choroba", + "y" : 2, + "name" : "E. Choroba" + }, + { + "y" : 4, + "name" : "Flavio Poletti", + "drilldown" : "Flavio Poletti" + }, + { + "y" : 2, + "name" : "James Smith", + "drilldown" : "James Smith" + }, + { + "y" : 2, + "name" : "Jan Krnavek", + "drilldown" : "Jan Krnavek" + }, + { + "drilldown" : "Jason Messer", + "y" : 2, + "name" : "Jason Messer" + }, + { + "drilldown" : "Jorg Sommrey", + "y" : 2, + "name" : "Jorg Sommrey" + }, + { + "drilldown" : "Julio de Castro", + "y" : 4, + "name" : "Julio de Castro" + }, + { + "drilldown" : "Kang-min Liu", + "y" : 2, + "name" : "Kang-min Liu" + }, + { + "name" : "Laurent Rosenfeld", + "y" : 5, + "drilldown" : "Laurent Rosenfeld" + }, + { + "drilldown" : "Lubos Kolouch", + "y" : 2, + "name" : "Lubos Kolouch" + }, + { + "drilldown" : "Mark Anderson", + "name" : "Mark Anderson", + "y" : 2 + }, + { + "drilldown" : "Markus Holzer", + "name" : "Markus Holzer", + "y" : 4 + }, + { + "drilldown" : "Mohammad S Anwar", + "name" : "Mohammad S Anwar", + "y" : 4 + }, + { + "drilldown" : "Myoungjin Jeon", + "name" : "Myoungjin Jeon", + "y" : 4 + }, + { + "y" : 2, + "name" : "Niels van Dijke", + "drilldown" : "Niels van Dijke" + }, + { + "name" : "Nuno Vieira", + "y" : 2, + "drilldown" : "Nuno Vieira" + }, + { + "drilldown" : "Pete Houston", + "y" : 2, + "name" : "Pete Houston" + }, + { + "name" : "Richard Park", + "y" : 2, + "drilldown" : "Richard Park" + }, + { + "drilldown" : "Roger Bell_West", + "y" : 5, + "name" : "Roger Bell_West" + }, + { + "name" : "Shahed Nooshmand", + "y" : 3, + "drilldown" : "Shahed Nooshmand" + }, + { + "name" : "Shawn Wagner", + "y" : 2, + "drilldown" : "Shawn Wagner" + }, + { + "name" : "Simon Green", + "y" : 3, + "drilldown" : "Simon Green" + }, + { + "y" : 2, + "name" : "Simon Proctor", + "drilldown" : "Simon Proctor" + }, + { + "drilldown" : "Steven Wilson", + "y" : 1, + "name" : "Steven Wilson" + }, + { + "y" : 4, + "name" : "Ulrich Rieke", + "drilldown" : "Ulrich Rieke" + }, + { + "drilldown" : "Vinod Kumar K", + "name" : "Vinod Kumar K", + "y" : 1 + }, + { + "name" : "Walt Mankowski", + "y" : 3, + "drilldown" : "Walt Mankowski" + }, + { + "y" : 2, + "name" : "Wanderdoc", + "drilldown" : "Wanderdoc" + } + ] + } + ], + "xAxis" : { + "type" : "category" + }, + "tooltip" : { + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "followPointer" : 1 + }, "drilldown" : { "series" : [ { - "name" : "Abigail", "id" : "Abigail", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Abigail" }, { + "id" : "Adam Russell", + "name" : "Adam Russell", "data" : [ [ "Perl", @@ -24,23 +267,21 @@ "Blog", 1 ] - ], - "name" : "Adam Russell", - "id" : "Adam Russell" + ] }, { + "name" : "Alexander Pankoff", "data" : [ [ "Perl", 2 ] ], - "name" : "Alexander Pankoff", "id" : "Alexander Pankoff" }, { - "name" : "Andinus", "id" : "Andinus", + "name" : "Andinus", "data" : [ [ "Perl", @@ -53,8 +294,6 @@ ] }, { - "id" : "Andrew Shitov", - "name" : "Andrew Shitov", "data" : [ [ "Raku", @@ -64,11 +303,13 @@ "Blog", 1 ] - ] + ], + "name" : "Andrew Shitov", + "id" : "Andrew Shitov" }, { - "name" : "Anton Fedotov", "id" : "Anton Fedotov", + "name" : "Anton Fedotov", "data" : [ [ "Perl", @@ -77,6 +318,7 @@ ] }, { + "name" : "Arne Sommer", "data" : [ [ "Perl", @@ -91,10 +333,11 @@ 1 ] ], - "name" : "Arne Sommer", "id" : "Arne Sommer" }, { + "id" : "Athanasius", + "name" : "Athanasius", "data" : [ [ "Perl", @@ -104,38 +347,44 @@ "Raku", 2 ] - ], - "id" : "Athanasius", - "name" : "Athanasius" + ] }, { "id" : "Bob Lied", - "name" : "Bob Lied", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Bob Lied" }, { - "id" : "Cheok-Yin Fung", - "name" : "Cheok-Yin Fung", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Cheok-Yin Fung", + "id" : "Cheok-Yin Fung" }, { + "id" : "Colin Crain", "data" : [ [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ "Blog", 1 ] ], - "id" : "Colin Crain", "name" : "Colin Crain" }, { @@ -149,24 +398,24 @@ "id" : "Dave Cross" }, { + "name" : "Dave Jacoby", "data" : [ [ "Perl", 2 ] ], - "id" : "Dave Jacoby", - "name" : "Dave Jacoby" + "id" : "Dave Jacoby" }, { + "id" : "E. Choroba", + "name" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ], - "id" : "E. Choroba", - "name" : "E. Choroba" + ] }, { "id" : "Flavio Poletti", @@ -183,24 +432,24 @@ ] }, { + "id" : "James Smith", + "name" : "James Smith", "data" : [ [ "Perl", 2 ] - ], - "name" : "James Smith", - "id" : "James Smith" + ] }, { "name" : "Jan Krnavek", - "id" : "Jan Krnavek", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Jan Krnavek" }, { "id" : "Jason Messer", @@ -213,8 +462,8 @@ ] }, { - "name" : "Jorg Sommrey", "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey", "data" : [ [ "Perl", @@ -233,20 +482,22 @@ 2 ] ], - "id" : "Julio de Castro", - "name" : "Julio de Castro" + "name" : "Julio de Castro", + "id" : "Julio de Castro" }, { "name" : "Kang-min Liu", - "id" : "Kang-min Liu", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Kang-min Liu" }, { + "id" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld", "data" : [ [ "Perl", @@ -260,31 +511,31 @@ "Blog", 1 ] - ], - "id" : "Laurent Rosenfeld", - "name" : "Laurent Rosenfeld" + ] }, { + "id" : "Lubos Kolouch", + "name" : "Lubos Kolouch", "data" : [ [ "Perl", 2 ] - ], - "name" : "Lubos Kolouch", - "id" : "Lubos Kolouch" + ] }, { + "id" : "Mark Anderson", + "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ], - "name" : "Mark Anderson", - "id" : "Mark Anderson" + ] }, { + "id" : "Markus Holzer", + "name" : "Markus Holzer", "data" : [ [ "Perl", @@ -294,11 +545,10 @@ "Raku", 2 ] - ], - "id" : "Markus Holzer", - "name" : "Markus Holzer" + ] }, { + "name" : "Mohammad S Anwar", "data" : [ [ "Perl", @@ -309,10 +559,10 @@ 2 ] ], - "name" : "Mohammad S Anwar", "id" : "Mohammad S Anwar" }, { + "id" : "Myoungjin Jeon", "data" : [ [ "Perl", @@ -323,42 +573,41 @@ 2 ] ], - "id" : "Myoungjin Jeon", "name" : "Myoungjin Jeon" }, { + "id" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] ], - "id" : "Niels van Dijke", "name" : "Niels van Dijke" }, { - "id" : "Nuno Vieira", "name" : "Nuno Vieira", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Nuno Vieira" }, { + "id" : "Pete Houston", + "name" : "Pete Houston", "data" : [ [ "Perl", 2 ] - ], - "name" : "Pete Houston", - "id" : "Pete Houston" + ] }, { - "name" : "Richard Park", "id" : "Richard Park", + "name" : "Richard Park", "data" : [ [ "Raku", @@ -371,6 +620,8 @@ ] }, { + "id" : "Roger Bell_West", + "name" : "Roger Bell_West", "data" : [ [ "Perl", @@ -384,12 +635,9 @@ "Blog", 1 ] - ], - "name" : "Roger Bell_West", - "id" : "Roger Bell_West" + ] }, { - "name" : "Shahed Nooshmand", "id" : "Shahed Nooshmand", "data" : [ [ @@ -400,21 +648,20 @@ "Blog", 1 ] - ] + ], + "name" : "Shahed Nooshmand" }, { + "id" : "Shawn Wagner", + "name" : "Shawn Wagner", "data" : [ [ "Perl", 2 ] - ], - "id" : "Shawn Wagner", - "name" : "Shawn Wagner" + ] }, { - "id" : "Simon Green", - "name" : "Simon Green", "data" : [ [ "Perl", @@ -424,30 +671,31 @@ "Blog", 1 ] - ] + ], + "name" : "Simon Green", + "id" : "Simon Green" }, { - "name" : "Simon Proctor", - "id" : "Simon Proctor", "data" : [ [ "Raku", 2 |
