diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-09-01 13:35:51 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-09-01 13:35:51 +0100 |
| commit | 05c3b536c5ced329f2319039ee87c250091fd843 (patch) | |
| tree | e567be88cf6ec00a127220258d914a85128db2bd | |
| parent | 593bff55eb416106db7260950715a4ca15732a92 (diff) | |
| download | perlweeklychallenge-club-05c3b536c5ced329f2319039ee87c250091fd843.tar.gz perlweeklychallenge-club-05c3b536c5ced329f2319039ee87c250091fd843.tar.bz2 perlweeklychallenge-club-05c3b536c5ced329f2319039ee87c250091fd843.zip | |
- Added solutions by Ulrich Rieke.
| -rw-r--r-- | challenge-128/ulrich-rieke/perl/ch-2.pl | 102 | ||||
| -rw-r--r-- | challenge-128/ulrich-rieke/raku/ch-2.raku | 69 | ||||
| -rw-r--r-- | stats/pwc-current.json | 203 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 92 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 936 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 406 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 26 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 24 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 112 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 108 | ||||
| -rw-r--r-- | stats/pwc-summary-211-240.json | 100 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 122 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 98 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 110 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 524 |
15 files changed, 1611 insertions, 1421 deletions
diff --git a/challenge-128/ulrich-rieke/perl/ch-2.pl b/challenge-128/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..ff53840cd2 --- /dev/null +++ b/challenge-128/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,102 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; +use List::Util qw ( min ) ; + +#count the number of 0's which are directly right of a given 0 +sub countNeighbouringZeroes { + my $matrix = shift ; + my $row = shift ; + my $col = shift ; + my $sum = 1 ; + my $totalCols = scalar @{$matrix->[0]} ; + $col++ ; + while ( $col < $totalCols ) { + if ( $matrix->[$row]->[$col] eq '0' ) { + $sum++ ; + $col++ ; + } + else { + last ; + } + } + return $sum ; +} + +#count the 0's in a given column, starting at a particular row +sub countZeroesInColumn { + my $matrix = shift ; + my $row = shift ; + my $col = shift ; + my $sum = 0 ; + if ( $matrix->[$row]->[$col] eq '1' ) { + return 0 ; + } + else { + $sum = 1 ; + my $len = scalar @{$matrix} ; + $row++ ; + while ( $row < $len ) { + if ( $matrix->[$row]->[$col] eq '0' ) { + $sum++ ; + } + $row++ ; + } + return $sum ; + } +} + +say "Enter 1's and 0's, separated by a blank , end to end!" ; +my $line = <STDIN> ; +chomp $line ; +my @matrix ; +while ( $line ne "end" ) { + if ( $line =~ /([01]\s)+/ ) { + my @submatrix = split( /\s/ , $line ) ; + push @matrix , \@submatrix ; + } + else { + say "Enter 1's and 0's, separated by a blank, [ and ] at start a. end!" ; + } + $line = <STDIN> ; + chomp $line ; +} +my $rows = scalar @matrix ; # number of rows in the matrix +my $cols = scalar @{$matrix[0]} ; #number of columns in the matrix +my @zerofields ; #this array contains the widths and depths of submatrixes of 0's +#starting at a given row and column +#now we traverse the matrix row by row, column by column and look for neighbouring +#0's in the row and count the 0's in the respective columns +for my $row ( 0 .. $rows - 2 ) { + for my $col ( 0 .. $cols - 2 ) { + if ( $matrix[ $row ]->[$col] eq '0' ) { + my $colAdvances = countNeighbouringZeroes( \@matrix, $row , $col ) ; + my @zeroesInNeighbouringColumns ; + my $currentCol = $col ; + for my $i ( 0 .. $colAdvances - 1 ) { + my $zeroes = countZeroesInColumn( \@matrix, $row , $currentCol + $i ) ; + push @zeroesInNeighbouringColumns , $zeroes ; + push @zerofields, [ 1 , $zeroes ] ; + } +#a submatrix can only be as deep as the minimum number of 0's in a range of columns +#we also store the number of 0's in a given column + my $minzeroes = min @zeroesInNeighbouringColumns ; + if ( $colAdvances && $minzeroes ) { + push @zerofields , [ $colAdvances , $minzeroes ] ; + } + } + } +} +#we sort by the product of width and depth in descending order +sub byFields { ($b->[0] * $b->[1]) <=> ($a->[0] * $a->[1]) || $b->[0] <=> $a->[0]} ; +my @sorted = sort byFields @zerofields ; +my $printRow = $sorted[0]->[1] ; +my $printCol = $sorted[0]->[0] ; +for (1 .. $printRow ) { + print "[ " ; + for ( 1 .. $printCol ) { + print "0 " ; + } + say ']' ; +} diff --git a/challenge-128/ulrich-rieke/raku/ch-2.raku b/challenge-128/ulrich-rieke/raku/ch-2.raku new file mode 100644 index 0000000000..d49e039994 --- /dev/null +++ b/challenge-128/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,69 @@ +use v6 ; + +sub enterTimes( ) { +#regex for valid times + my $point_in_time = /^^'(' ((0<[0..9]> || 1<[0..9]> || 2<[0..3]> ) ':' + <[0..5]><[0..9]>','* \s* )+ ')' $$/ ; + say "Enter times, starting with a ( and ending with a ), pattern : + <hours>:<minutes>" ; + my $line = $*IN.get ; + my @times ; + while ( $line !~~ /<$point_in_time>/ ) { + say "Please enter times , starting with a ( and ending " + ~ "with )!" ; + say "see above for general pattern!" ; + $line = $*IN.get ; + } + if ( $line ~~ /<$point_in_time>/ ) { + given $line { +#find all given times by collecting them into an array + my @matches = m:global/\d ** 2 ':' \d ** 2 / ; + my $len = @matches.elems ; + for (0 .. $len - 1 ) -> $i { #find hours and minutes + my ( $hours , $minutes ) = @matches[ $i ].split( /':'/ ) ; +#create a DateTime object + my $time = DateTime.new( year => 2021 , month => 8 , + day => 30 , hour => +$hours , minute => +$minutes ) ; + @times.push( $time ) ; + } + } + } + return @times ; +} + +sub MAIN( ) { + say "Enter arrival times, they should be ordered by time of arrival!" ; + my @arrivals = enterTimes( ) ; + my $len = @arrivals.elems ; + for (0 .. $len - 2 ) -> $i { + unless ( @arrivals[ $i ] < @arrivals[ $i + 1 ] ) { + say "arrivals should be ordered!" ; + say "Enter new arrival times!" ; + @arrivals = enterTimes( ) ; + } + } + say "Enter departure times, starting with ( and ending with ), pattern " ~ + "<hours>:<minutes> " ; + my @departures = enterTimes( ) ; + my $dlen = @departures.elems ; + while ( $dlen != $len ) { + say "There should be as many departures as arrivals!" ; + @departures = enterTimes( ) ; + $dlen = @departures.elems ; + } + for ( 0 .. $len - 1 ) -> $i { + if ( @departures[ $i ] < @arrivals[ $i ] ) { + say "train can't leave before arriving!" ; + die "now I am leaving!" ; + } + } + my @trainsInStation ;#how many trains are in station when a new one arrives? + for ( 1 .. $len - 1 ) -> $i { +#all those trains who leave after the new train arrives are still in station + @trainsInStation.push( @departures[0..$i - 1].grep( {$_ > + @arrivals[ $i ]} ).elems ) ; + } +#the maximum number of platforms is the maximum number of trains waiting at +#station at any one time + 1, the minimum number of platforms + say @trainsInStation.max + 1 ; +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index ba209e6b76..050ce3520b 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,77 +1,18 @@ { - "series" : [ - { - "data" : [ - { - "name" : "E. Choroba", - "y" : 2, - "drilldown" : "E. Choroba" - }, - { - "name" : "Flavio Poletti", - "drilldown" : "Flavio Poletti", - "y" : 6 - }, - { - "y" : 3, - "drilldown" : "James Smith", - "name" : "James Smith" - }, - { - "name" : "Luca Ferrari", - "y" : 4, - "drilldown" : "Luca Ferrari" - }, - { - "drilldown" : "Mark Anderson", - "y" : 2, - "name" : "Mark Anderson" - }, - { - "name" : "Peter Campbell Smith", - "y" : 1, - "drilldown" : "Peter Campbell Smith" - }, - { - "name" : "Roger Bell_West", - "y" : 4, - "drilldown" : "Roger Bell_West" - }, - { - "drilldown" : "Simon Green", - "y" : 3, - "name" : "Simon Green" - }, - { - "drilldown" : "Stuart Little", - "y" : 4, - "name" : "Stuart Little" - } - ], - "name" : "The Weekly Challenge - 128", - "colorByPoint" : 1 - } - ], - "plotOptions" : { - "series" : { - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - }, - "borderWidth" : 0 - } + "title" : { + "text" : "The Weekly Challenge - 128" }, "drilldown" : { "series" : [ { + "name" : "E. Choroba", + "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ], - "name" : "E. Choroba", - "id" : "E. Choroba" + ] }, { "data" : [ @@ -93,6 +34,7 @@ }, { "name" : "James Smith", + "id" : "James Smith", "data" : [ [ "Perl", @@ -102,12 +44,9 @@ "Blog", 1 ] - ], - "id" : "James Smith" + ] }, { - "id" : "Luca Ferrari", - "name" : "Luca Ferrari", "data" : [ [ "Raku", @@ -117,30 +56,31 @@ "Blog", 2 ] - ] + ], + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" }, { - "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] ], - "name" : "Mark Anderson" + "name" : "Mark Anderson", + "id" : "Mark Anderson" }, { - "id" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith", "data" : [ [ "Perl", 1 ] - ] + ], + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith" }, { - "id" : "Roger Bell_West", "data" : [ [ "Perl", @@ -151,10 +91,10 @@ 2 ] ], + "id" : "Roger Bell_West", "name" : "Roger Bell_West" }, { - "id" : "Simon Green", "data" : [ [ "Perl", @@ -165,9 +105,11 @@ 1 ] ], + "id" : "Simon Green", "name" : "Simon Green" }, { + "name" : "Stuart Little", "id" : "Stuart Little", "data" : [ [ @@ -178,34 +120,111 @@ "Raku", 2 ] - ], - "name" : "Stuart Little" + ] + }, + { + "name" : "Ulrich Rieke", + "id" : "Ulrich Rieke", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ] + ] } ] }, - "title" : { - "text" : "The Weekly Challenge - 128" + "legend" : { + "enabled" : 0 + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } }, "chart" : { "type" : "column" }, - "tooltip" : { - "followPointer" : 1, - "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/>" - }, "xAxis" : { "type" : "category" }, "subtitle" : { - "text" : "[Champions: 9] Last updated at 2021-09-01 09:05:23 GMT" + "text" : "[Champions: 10] Last updated at 2021-09-01 12:15:42 GMT" }, - "legend" : { - "enabled" : 0 - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "series" : [ + { + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 128", + "data" : [ + { + "drilldown" : "E. Choroba", + "name" : "E. Choroba", + "y" : 2 + }, + { + "name" : "Flavio Poletti", + "drilldown" : "Flavio Poletti", + "y" : 6 + }, + { + "y" : 3, + "name" : "James Smith", + "drilldown" : "James Smith" + }, + { + "drilldown" : "Luca Ferrari", + "name" : "Luca Ferrari", + "y" : 4 + }, + { + "y" : 2, + "drilldown" : "Mark Anderson", + "name" : "Mark Anderson" + }, + { + "name" : "Peter Campbell Smith", + "drilldown" : "Peter Campbell Smith", + "y" : 1 + }, + { + "y" : 4, + "drilldown" : "Roger Bell_West", + "name" : "Roger Bell_West" + }, + { + "name" : "Simon Green", + "drilldown" : "Simon Green", + "y" : 3 + }, + { + "y" : 4, + "name" : "Stuart Little", + "drilldown" : "Stuart Little" + }, + { + "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke", + "y" : 2 + } + ] + } + ], + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 } + }, + "tooltip" : { + "followPointer" : 1, + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index f85b6c6298..80833acf4d 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,49 +1,7 @@ { - "subtitle" : { - "text" : "Last updated at 2021-09-01 09:05:23 GMT" - }, - "xAxis" : { - "labels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - } - }, - "type" : "category" - }, - "yAxis" : { - "title" : { - "text" : null - }, - "min" : 0 - }, - "legend" : { - "enabled" : "false" - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2021]" - }, - "chart" : { - "type" : "column" - }, "series" : [ { "name" : "Contributions", - "dataLabels" : { - "rotation" : -90, - "color" : "#FFFFFF", - "enabled" : "true", - "align" : "right", - "format" : "{point.y:.0f}", - "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" - }, - "y" : 10 - }, "data" : [ [ "Blog", @@ -51,13 +9,55 @@ ], [ "Perl", - 6124 + 6125 ], [ "Raku", - 3787 + 3788 ] - ] + ], + "dataLabels" : { + "y" : 10, + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + }, + "format" : "{point.y:.0f}", + "rotation" : -90, + "color" : "#FFFFFF", + "align" : "right", + "enabled" : "true" + } + } + ], + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, + "yAxis" : { + "min" : 0, + "title" : { + "text" : null } - ] + }, + "legend" : { + "enabled" : "false" + }, + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2021]" + }, + "chart" : { + "type" : "column" + }, + "xAxis" : { + "labels" : { + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + } + }, + "type" : "category" + }, + "subtitle" : { + "text" : "Last updated at 2021-09-01 12:15:42 GMT" + } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index fd43e3d9ea..82d19e1e10 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,22 +1,11 @@ { - "tooltip" : { - "followPointer" : "true", - "headerFormat" : "<span style=\"font-size:11px\"></span>", - "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>" - }, - "legend" : { - "enabled" : "false" - }, "yAxis" : { "title" : { "text" : "Total Solutions" } }, - "xAxis" : { - "type" : "category" - }, - "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2021-09-01 09:05:23 GMT" + "legend" : { + "enabled" : "false" }, "drilldown" : { "series" : [ @@ -35,12 +24,12 @@ 11 ] ], - "name" : "001", - "id" : "001" + "id" : "001", + "name" : "001" }, { - "id" : "002", "name" : "002", + "id" : "002", "data" : [ [ "Perl", @@ -57,6 +46,8 @@ ] }, { + "id" : "003", + "name" : "003", "data" : [ [ "Perl", @@ -70,9 +61,7 @@ "Blog", 9 ] - ], - "name" : "003", - "id" : "003" + ] }, { "id" : "004", @@ -111,6 +100,7 @@ ] }, { + "name" : "006", "id" : "006", "data" : [ [ @@ -125,12 +115,9 @@ "Blog", 7 ] - ], - "name" : "006" + ] }, { - "id" : "007", - "name" : "007", "data" : [ [ "Perl", @@ -144,10 +131,13 @@ "Blog", 10 ] - ] + ], + "name" : "007", + "id" : "007" }, { "name" : "008", + "id" : "008", "data" : [ [ "Perl", @@ -161,11 +151,11 @@ "Blog", 12 ] - ], - "id" : "008" + ] }, { "name" : "009", + "id" : "009", "data" : [ [ "Perl", @@ -179,11 +169,11 @@ "Blog", 13 ] - ], - "id" : "009" + ] }, { "id" : "010", + "name" : "010", "data" : [ [ "Perl", @@ -197,10 +187,11 @@ "Blog", 11 ] - ], - "name" : "010" + ] }, { + "name" : "011", + "id" : "011", "data" : [ [ "Perl", @@ -214,12 +205,9 @@ "Blog", 10 ] - ], - "name" : "011", - "id" : "011" + ] }, { - "name" : "012", "data" : [ [ "Perl", @@ -234,10 +222,12 @@ 11 ] ], - "id" : "012" + "id" : "012", + "name" : "012" }, { "name" : "013", + "id" : "013", "data" : [ [ "Perl", @@ -251,11 +241,9 @@ "Blog", 13 ] - ], - "id" : "013" + ] }, { - "id" : "014", "data" : [ [ "Perl", @@ -270,9 +258,11 @@ 15 ] ], + "id" : "014", "name" : "014" }, { + "id" : "015", "name" : "015", "data" : [ [ @@ -287,10 +277,11 @@ "Blog", 15 ] - ], - "id" : "015" + ] }, { + "name" : "016", + "id" : "016", "data" : [ [ "Perl", @@ -304,13 +295,9 @@ "Blog", 12 ] - ], - "name" : "016", - "id" : "016" + ] }, { - "id" : "017", - "name" : "017", "data" : [ [ "Perl", @@ -324,9 +311,13 @@ "Blog", 12 ] - ] + ], + "name" : "017", + "id" : "017" }, { + "id" : "018", + "name" : "018", "data" : [ [ "Perl", @@ -340,9 +331,7 @@ "Blog", 14 ] - ], - "name" : "018", - "id" : "018" + ] }, { "data" : [ @@ -359,8 +348,8 @@ 13 ] ], - "name" : "019", - "id" : "019" + "id" : "019", + "name" : "019" }, { "id" : "020", @@ -381,8 +370,6 @@ ] }, { - "id" : "021", - "name" : "021", "data" : [ [ "Perl", @@ -396,11 +383,11 @@ "Blog", 10 ] - ] + ], + "name" : "021", + "id" : "021" }, { - "id" : "022", - "name" : "022", "data" : [ [ "Perl", @@ -414,7 +401,9 @@ "Blog", 10 ] - ] + ], + "name" : "022", + "id" : "022" }, { "data" : [ @@ -435,7 +424,6 @@ "id" : "023" }, { - "id" : "024", "data" : [ [ "Perl", @@ -450,10 +438,10 @@ 11 ] ], - "name" : "024" + "name" : "024", + "id" : "024" }, { - "id" : "025", "data" : [ [ "Perl", @@ -468,10 +456,10 @@ 12 ] ], - "name" : "025" + "name" : "025", + "id" : "025" }, { - "name" : "026", "data" : [ [ "Perl", @@ -486,10 +474,12 @@ 10 ] ], - "id" : "026" + "id" : "026", + "name" : "026" }, { "name" : "027", + "id" : "027", "data" : [ [ "Perl", @@ -503,10 +493,11 @@ "Blog", 9 ] - ], - "id" : "027" + ] }, { + "name" : "028", + "id" : "028", "data" : [ [ "Perl", @@ -520,11 +511,10 @@ "Blog", 9 ] - ], - "name" : "028", - "id" : "028" + ] }, { + "id" : "029", "name" : "029", "data" : [ [ @@ -539,10 +529,10 @@ "Blog", 12 ] - ], - "id" : "029" + ] }, { + "id" : "030", "name" : "030", "data" : [ [ @@ -557,10 +547,11 @@ "Blog", 10 ] - ], - "id" : "030" + ] }, { + "name" : "031", + "id" : "031", "data" : [ [ "Perl", @@ -574,11 +565,11 @@ "Blog", 9 ] - ], - "name" : "031", - "id" : "031" + ] }, { + "name" : "032", + "id" : "032", "data" : [ [ "Perl", @@ -592,12 +583,9 @@ "Blog", 10 ] - ], - "name" : "032", - "id" : "032" + ] }, { - "id" : "033", "data" : [ [ "Perl", @@ -612,10 +600,10 @@ 10 ] ], + "id" : "033", "name" : "033" }, { - "id" : "034", "data" : [ [ "Perl", @@ -630,11 +618,10 @@ 11 ] ], + "id" : "034", "name" : "034" }, { - "id" : "035", - "name" : "035", "data" : [ [ "Perl", @@ -648,9 +635,13 @@ "Blog", 9 ] - ] + ], + "id" : "035", + "name" : "035" }, { + "id" : "036", + "name" : "036", "data" : [ [ "Perl", @@ -664,12 +655,9 @@ "Blog", 11 ] - ], - "name" : "036", - "id" : "036" + ] }, { - "name" : "037", "data" : [ [ "Perl", @@ -684,10 +672,10 @@ 9 ] ], - "id" : "037" + "id" : "037", + "name" : "037" }, { - "name" : "038", "data" : [ [ "Perl", @@ -702,11 +690,10 @@ 12 ] ], + "name" : "038", |
