diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-05-18 11:54:30 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-05-18 11:54:30 +0100 |
| commit | 78fe2f72354f77a833346bcf8571780c6fd2be5e (patch) | |
| tree | 7e12b9201969ab64dc6a11ccab7acbf13b813077 | |
| parent | 20b2caef18b138191e9c9263a35abfd6fc2b9249 (diff) | |
| download | perlweeklychallenge-club-78fe2f72354f77a833346bcf8571780c6fd2be5e.tar.gz perlweeklychallenge-club-78fe2f72354f77a833346bcf8571780c6fd2be5e.tar.bz2 perlweeklychallenge-club-78fe2f72354f77a833346bcf8571780c6fd2be5e.zip | |
- Added solutions by Javier Luque.
| -rw-r--r-- | challenge-061/javier-luque/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-061/javier-luque/perl/ch-1.pl | 46 | ||||
| -rw-r--r-- | challenge-061/javier-luque/perl/ch-2.pl | 59 | ||||
| -rw-r--r-- | challenge-061/javier-luque/raku/ch-1.p6 | 42 | ||||
| -rw-r--r-- | challenge-061/javier-luque/raku/ch-2.p6 | 49 | ||||
| -rw-r--r-- | stats/pwc-current.json | 83 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 64 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 870 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 724 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 48 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 60 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 44 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 52 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 110 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 38 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 374 |
16 files changed, 1442 insertions, 1222 deletions
diff --git a/challenge-061/javier-luque/blog.txt b/challenge-061/javier-luque/blog.txt new file mode 100644 index 0000000000..af053ded18 --- /dev/null +++ b/challenge-061/javier-luque/blog.txt @@ -0,0 +1 @@ +https://perlchallenges.wordpress.com/2020/05/18/perl-weekly-challenge-061/ diff --git a/challenge-061/javier-luque/perl/ch-1.pl b/challenge-061/javier-luque/perl/ch-1.pl new file mode 100644 index 0000000000..f2f77436bf --- /dev/null +++ b/challenge-061/javier-luque/perl/ch-1.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl +# Test: ./ch-1.pl 30 +use strict; +use warnings; +use feature qw /say/; + +say max_product([ 2, 5, -1, 3 ]); + +sub max_product { + my $list = shift; + + # Index of the array that will return + # the max product + my $left = 0; + my $right = scalar(@$list); + + # Max product + my $max_product = 1; + + # Loop through the list + for (my $i = 0; $i < scalar(@$list); $i++ ) { + my $j = $i; + + # Temp variable + my $current_product = 1; + + # Loop through the list another time + while ($j < scalar(@$list)) { + $current_product = + $current_product * $list->[$j]; + + if ($current_product >= $max_product) { + $max_product = $current_product; + $left = $i; + $right = $j; + } + + $j++; + } + } + + return '[' . + (join ', ', @{$list}[$left .. $right]) . + ']' . ' which gives a maximum product of ' . + $max_product; +} diff --git a/challenge-061/javier-luque/perl/ch-2.pl b/challenge-061/javier-luque/perl/ch-2.pl new file mode 100644 index 0000000000..4e6f94c681 --- /dev/null +++ b/challenge-061/javier-luque/perl/ch-2.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl +# Test: ./ch-2.pl +use strict; +use warnings; +use feature qw /say/; +use Algorithm::Combinatorics qw(combinations); + +my $ip_address = $ARGV[0] || '25525511135'; +partition_ip_string($ip_address); + +# Partition the ip string +sub partition_ip_string { + my $string = shift; + my $length = length($string) - 2; + + # Validate string + return undef if + ( length($string) < 4 || + length($string) > 12 || + !($string =~ /^\d+$/) + ); + + # Find all the combinations for the possible ips + my @dot_positions = (0 .. $length); + my $iter = combinations(\@dot_positions, 3); + + # Process the combinations + while (my $combos = $iter->next) { + my $to_test = $string; + my $offset = 0; + + for my $dot_position (@$combos) { + my $position = + ($dot_position + $offset) + 1; + + # Append to the test string; + $to_test = + (substr $to_test, 0, $position) + . '.' . + (substr $to_test, $position); + + # Offset the string + $offset++; + } + + say $to_test + if (validate_ip_string($to_test)); + } +} + +# Validate the IP String +sub validate_ip_string { + for my $digit (split('\.', shift)) { + return 0 if ($digit > 255); + return 0 if ($digit =~ /^0\d+$/); + } + + return 1; +} diff --git a/challenge-061/javier-luque/raku/ch-1.p6 b/challenge-061/javier-luque/raku/ch-1.p6 new file mode 100644 index 0000000000..000a8b6140 --- /dev/null +++ b/challenge-061/javier-luque/raku/ch-1.p6 @@ -0,0 +1,42 @@ +# Test: perl6 ch-1.p6 +sub MAIN() { + say max-product([ 2, 5, -1, 3 ]); +} + +sub max-product(@list) { + + # Index of the array that will return + # the max product + my $left = 0; + my $right = @list.elems; + + # Max product + my $max_product = 1; + + # Loop through the list + for ^@list -> $i { + my $j = $i; + + # Temp variable + my $current_product = 1; + + # Loop through the list another time + while ($j < @list.elems) { + $current_product = + $current_product * @list[$j]; + + if ($current_product >= $max_product) { + $max_product = $current_product; + $left = $i; + $right = $j; + } + + $j++; + } + } + + return '[' ~ + @list[$left .. $right].join(', ') ~ + ']' ~ ' which gives a maximum product of ' ~ + $max_product;; +} diff --git a/challenge-061/javier-luque/raku/ch-2.p6 b/challenge-061/javier-luque/raku/ch-2.p6 new file mode 100644 index 0000000000..0d06952652 --- /dev/null +++ b/challenge-061/javier-luque/raku/ch-2.p6 @@ -0,0 +1,49 @@ +# Test: perl6 ch-2.p6 +multi MAIN() { + MAIN('25525511135'); +} + +multi MAIN(Str $str) { + partition-ip-string($str); +} + +# Partition the ip string +sub partition-ip-string (Str $str) { + my $length = $str.chars - 2; + + # Find all the combinations for the possible ips + my @dot_positions = (0 .. $length); + my @combos = @dot_positions.combinations: 3; + + # Process the combinations + for @combos -> @combo { + my $to_test = $str; + my $offset = 0; + + for (@combo) -> $dot_position { + my $position = + ($dot_position + $offset) + 1; + + # Append to the test string; + $to_test = + $to_test.substr(0, $position) + ~ '.' ~ + $to_test.substr($position); + + # Offset the string + $offset++; + } + + say $to_test + if (validate-ip-string($to_test)); + } +} + +# Validate the IP String +sub validate-ip-string(Str $str) { + for $str.split('.') -> $digit { + return False if ($digit > 255); + return False if ($digit ~~ /^0\d+$/); + } + return True; +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index c020945666..e564fdfa1d 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,22 +1,36 @@ { - "chart" : { - "type" : "column" + "tooltip" : { + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "followPointer" : 1, + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" }, - "legend" : { - "enabled" : 0 + "subtitle" : { + "text" : "[Champions: 3] Last updated at 2020-05-18 10:54:07 GMT" }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - } - } + "title" : { + "text" : "Perl Weekly Challenge - 061" }, "drilldown" : { "series" : [ { + "name" : "Javier Luque", + "id" : "Javier Luque", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { "data" : [ [ "Perl", @@ -44,39 +58,48 @@ }, "series" : [ { - "colorByPoint" : 1, "name" : "Perl Weekly Challenge - 061", + "colorByPoint" : 1, "data" : [ { + "drilldown" : "Javier Luque", + "name" : "Javier Luque", + "y" : 5 + }, + { + "y" : 3, "drilldown" : "Roger Bell_West", - "name" : "Roger Bell_West", - "y" : 3 + "name" : "Roger Bell_West" }, { - "y" : 1, + "drilldown" : "Simon Proctor", "name" : "Simon Proctor", - "drilldown" : "Simon Proctor" + "y" : 1 } ] } ], - "xAxis" : { - "type" : "category" - }, - "subtitle" : { - "text" : "[Champions: 2] Last updated at 2020-05-18 09:01:06 GMT" - }, - "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 - }, - "title" : { - "text" : "Perl Weekly Challenge - 061" + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } + } }, "yAxis" : { "title" : { "text" : "Total Solutions" } + }, + "chart" : { + "type" : "column" + }, + "legend" : { + "enabled" : 0 + }, + "xAxis" : { + "type" : "category" } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 62336c3382..f016bf6a23 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,63 +1,63 @@ { + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, + "xAxis" : { + "type" : "category", + "labels" : { + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + } + } + }, + "chart" : { + "type" : "column" + }, + "legend" : { + "enabled" : "false" + }, "series" : [ { + "name" : "Contributions", "dataLabels" : { + "rotation" : -90, + "y" : 10, "style" : { "fontSize" : "13px", "fontFamily" : "Verdana, sans-serif" }, - "format" : "{point.y:.0f}", - "color" : "#FFFFFF", "enabled" : "true", + "color" : "#FFFFFF", "align" : "right", - "y" : 10, - "rotation" : -90 + "format" : "{point.y:.0f}" }, "data" : [ [ "Blog", - 691 + 692 ], [ "Perl", - 2542 + 2544 ], [ "Raku", - 1597 + 1599 ] - ], - "name" : "Contributions" + ] } ], - "xAxis" : { - "labels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - } - }, - "type" : "category" - }, - "subtitle" : { - "text" : "Last updated at 2020-05-18 09:01:06 GMT" - }, "yAxis" : { - "min" : 0, "title" : { "text" : null - } + }, + "min" : 0 + }, + "subtitle" : { + "text" : "Last updated at 2020-05-18 10:54:07 GMT" }, "title" : { "text" : "Perl Weekly Challenge Contributions [2019 - 2020]" - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, - "chart" : { - "type" : "column" - }, - "legend" : { - "enabled" : "false" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index cd72f88b64..eaadd3131c 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,10 +1,4 @@ { - "chart" : { - "type" : "column" - }, - "legend" : { - "enabled" : "false" - }, "plotOptions" : { "series" : { "dataLabels" : { @@ -14,10 +8,333 @@ "borderWidth" : 0 } }, + "series" : [ + { + "data" : [ + { + "name" : "#001", + "drilldown" : "001", + "y" : 142 + }, + { + "drilldown" : "002", + "name" : "#002", + "y" : 109 + }, + { + "drilldown" : "003", + "name" : "#003", + "y" : 71 + }, + { + "name" : "#004", + "drilldown" : "004", + "y" : 91 + }, + { + "y" : 72, + "name" : "#005", + "drilldown" : "005" + }, + { + "name" : "#006", + "drilldown" : "006", + "y" : 52 + }, + { + "y" : 59, + "drilldown" : "007", + "name" : "#007" + }, + { + "name" : "#008", + "drilldown" : "008", + "y" : 72 + }, + { + "name" : "#009", + "drilldown" : "009", + "y" : 68 + }, + { + "y" : 60, + "drilldown" : "010", + "name" : "#010" + }, + { + "drilldown" : "011", + "name" : "#011", + "y" : 79 + }, + { + "drilldown" : "012", + "name" : "#012", + "y" : 83 + }, + { + "drilldown" : "013", + "name" : "#013", + "y" : 76 + }, + { + "y" : 96, + "name" : "#014", + "drilldown" : "014" + }, + { + "drilldown" : "015", + "name" : "#015", + "y" : 93 + }, + { + "drilldown" : "016", + "name" : "#016", + "y" : 66 + }, + { + "drilldown" : "017", + "name" : "#017", + "y" : 79 + }, + { + "y" : 76, + "name" : "#018", + "drilldown" : "018" + }, + { + "y" : 97, + "name" : "#019", + "drilldown" : "019" + }, + { + "y" : 95, + "name" : "#020", + "drilldown" : "020" + }, + { + "name" : "#021", + "drilldown" : "021", + "y" : 67 + }, + { + "drilldown" : "022", + "name" : "#022", + "y" : 63 + }, + { + "drilldown" : "023", + "name" : "#023", + "y" : 91 + }, + { + "y" : 70, + "name" : "#024", + "drilldown" : "024" + }, + { + "drilldown" : "025", + "name" : "#025", + "y" : 55 + }, + { + "name" : "#026", + "drilldown" : "026", + "y" : 70 + }, + { + "name" : "#027", + "drilldown" : "027", + "y" : 58 + }, + { + "y" : 78, + "drilldown" : "028", + "name" : "#028" + }, + { + "y" : 77, + "name" : "#029", + "drilldown" : "029" + }, + { + "y" : 115, + "name" : "#030", + "drilldown" : "030" + }, + { + "name" : "#031", + "drilldown" : "031", + "y" : 87 + }, + { + "y" : 92, + "name" : "#032", + "drilldown" : "032" + }, + { + "name" : "#033", + "drilldown" : "033", + "y" : 108 + }, + { + "y" : 62, + "drilldown" : "034", + "name" : "#034" + }, + { + "y" : 62, + "drilldown" : "035", + "name" : "#035" + }, + { + "y" : 66, + "name" : "#036", + "drilldown" : "036" + }, + { + "y" : 65, + "name" : "#037", + "drilldown" : "037" + }, + { + "name" : "#038", + "drilldown" : "038", + "y" : 65 + }, + { + "y" : 60, + "drilldown" : "039", + "name" : "#039" + }, + { + "name" : "#040", + "drilldown" : "040", + "y" : 71 + }, + { + "name" : "#041", + "drilldown" : "041", + "y" : 74 + }, + { + "drilldown" : "042", + "name" : "#042", + "y" : 88 + }, + { + "y" : 66, + "drilldown" : "043", + "name" : "#043" + }, + { + "drilldown" : "044", + "name" : "#044", + "y" : 82 + }, + { + "y" : 94, + "drilldown" : "045", + "name" : "#045" + }, + { + "y" : 85, + "name" : "#046", + "drilldown" : "046" + }, + { + "drilldown" : "047", + "name" : "#047", + "y" : 82 + }, + { + "drilldown" : "048", + "name" : "#048", + "y" : 106 + }, + { + "drilldown" : "049", + "name" : "#049", + "y" : 85 + }, + { + "name" : "#050", + "drilldown" : "050", + "y" : 96 + }, + { + "name" : "#051", + "drilldown" : "051", + "y" : 87 + }, + { + "y" : 89, + "name" : "#052", + "drilldown" : "052" + }, + { + "name" : "#053", + "drilldown" : "053", + "y" : 99 + }, + { + "y" : 99, + "drilldown" : "054", + "name" : "#054" + }, + { + "drilldown" : "055", + "name" : "#055", + "y" : 86 + }, + { + "y" : 93, + "name" : "#056", + "drilldown" : "056" + }, + { + "drilldown" : "057", + "name" : "#057", + "y" : 78 + }, + { + "y" : 61, + "name" : "#058", + "drilldown" : "058" + }, + { + "name" : "#059", + "drilldown" : "059", + "y" : 82 + }, + { + "y" : 76, + "drilldown" : "060", + "name" : "#060" + }, + { + "y" : 9, + "name" : "#061", + "drilldown" : "061" + } + ], + "name" : "Perl Weekly Challenge Languages", + "colorByPoint" : "true" + } + ], + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "subtitle" : { + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2020-05-18 10:54:07 GMT" + }, + "title" : { + "text" : "Perl Weekly Challenge Language" + }, "drilldown" : { "series" : [ { - "name" : "001", "id" : "001", "data" : [ [ @@ -32,9 +349,12 @@ "Blog", 11 ] - ] + ], + "name" : "001" }, { + "name" : "002", + "id" : "002", "data" : [ [ "Perl", @@ -48,11 +368,10 @@ "Blog", 10 ] - ], - "id" : "002", - "name" : "002" + ] }, { + "id" : "003", "data" : [ [ "Perl", @@ -67,11 +386,9 @@ 9 ] ], - "id" : "003", "name" : "003" }, { - "id" : "004", "name" : "004", "data" : [ [ @@ -86,10 +403,10 @@ "Blog", 10 ] - ] + ], + "id" : "004" }, { - "id" : "005", "name" : "005", "data" : [ [ @@ -104,7 +421,8 @@ "Blog", 12 ] - ] + ], + "id" : "005" }, { "data" : [ @@ -139,10 +457,12 @@ 10 ] ], - "name" : "007", - "id" : "007" + "id" : "007", + "name" : "007" }, { + "name" : "008", + "id" : "008", "data" : [ [ "Perl", @@ -156,13 +476,11 @@ "Blog", 12 ] - ], - "name" : "008", - "id" : "008" + ] }, { - "id" : "009", "name" : "009", + "id" : "009", "data" : [ [ "Perl", @@ -179,6 +497,8 @@ ] }, { + "name" : "010", + "id" : "010", "data" : [ [ "Perl", @@ -192,13 +512,10 @@ "Blog", 11 ] - ], - "id" : "010", - "name" : "010" + ] }, { "id" : "011", - "name" : "011", "data" : [ [ "Perl", @@ -212,9 +529,11 @@ "Blog", 10 ] - ] + ], + "name" : "011" }, { + "id" : "012", "data" : [ [ "Perl", @@ -229,12 +548,10 @@ 11 ] ], - "name" : "012", - "id" : "012" + "name" : "012" }, { "id" : "013", - "name" : "013", "data" : [ [ "Perl", @@ -248,9 +565,12 @@ "Blog", 13 ] - ] + ], + "name" : "013" }, { + "name" : "014", + "id" : "014", "data" : [ [ "Perl", @@ -264,13 +584,11 @@ "Blog", 15 ] - ], - "id" : "014", - "name" : "014" + ] }, { - "id" : "015", "name" : "015", + "id" : "015", "data" : [ [ "Perl", @@ -287,6 +605,7 @@ ] }, { + "id" : "016", "data" : [ [ "Perl", @@ -301,11 +620,9 @@ 12 ] ], - "id" : "016", "name" : "016" }, { - "name" : "017", "id" : "017", "data" : [ [ @@ -320,7 +637,8 @@ "Blog", 12 ] - ] + ], + "name" : "017" }, { "name" : "018", @@ -341,8 +659,6 @@ ] }, { - "id" : "019", - "name" : "019", "data" : [ [ "Perl", @@ -356,9 +672,12 @@ "Blog", 13 ] - ] + ], + "id" : "019", + "name" : "019" }, { + "id" : "020", "data" : [ [ "Perl", @@ -373,11 +692,9 @@ 13 ] ], - "id" : "020", "name" : "020" }, { - "id" : "021", "name" : "021", "data" : [ [ @@ -392,7 +709,8 @@ "Blog", 10 ] - ] + ], + "id" : "021" }, { "name" : "022", @@ -431,6 +749,7 @@ ] }, { + "name" : "024", "data" : [ [ "Perl", @@ -445,10 +764,11 @@ 11 ] ], - "id" : "024", - "name" : "024" + "id" : "024" }, { + "name" : "025", + "id" : "025", "data" : [ [ "Perl", @@ -462,9 +782,7 @@ "Blog", 12 ] - ], - "name" : "025", - "id" : "025" + ] }, { "name" : "026", @@ -486,7 +804,6 @@ }, { "id" : "027", - "name" : "027", "data" : [ [ "Perl", @@ -500,11 +817,11 @@ "Blog", 9 ] - ] + ], + "name" : "027" }, { "name" : "028", - "id" : "028", "data" : [ [ "Perl", @@ -518,7 +835,8 @@ "Blog", 9 ] - ] + ], + "id" : "028" }, { "data" : [ @@ -539,8 +857,8 @@ "name" : "029" }, { - "id" : "030", "name" : |
