diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-29 19:58:42 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-29 19:58:42 +0100 |
| commit | 1d33e6293b7f2829eb3815cecc2112812dbc69b6 (patch) | |
| tree | a9a768f44bf6ce54165dabf0d6e6cfc8ad89f8e9 | |
| parent | b1cd8eaccef473671cddffe2a8fd68f8ed0d99ed (diff) | |
| download | perlweeklychallenge-club-1d33e6293b7f2829eb3815cecc2112812dbc69b6.tar.gz perlweeklychallenge-club-1d33e6293b7f2829eb3815cecc2112812dbc69b6.tar.bz2 perlweeklychallenge-club-1d33e6293b7f2829eb3815cecc2112812dbc69b6.zip | |
- Added blog post by Roger Bell_West.
- Added solutions by Paulo Custodio.
- Added solutions by Simon Green.
- Added solutions by Matthias Muth.
- Added solutions by Athanasius.
- Added solutions by Ulrich Rieke.
23 files changed, 2584 insertions, 2442 deletions
diff --git a/challenge-288/ulrich-rieke/rust/ch-2.rs b/challenge-288/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..f3c6c893a0 --- /dev/null +++ b/challenge-288/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,85 @@ +use std::{io , cmp} ; +use std::io::BufRead ; + +//find positions of all given letter in a block +fn find_positions( block : &Vec<&str> , letter : char) -> Vec<(usize , usize)> { + let mut all_positions : Vec<(usize , usize)> = Vec::new( ) ; + let len = block.len( ) ; + for n in 0..len { + let line : &str = &block[n] ; + line.chars( ).enumerate( ).map( |tup| (n , tup.0 , tup.1 ) ).filter( + |&trip| trip.2 == letter ).map( |trip| (trip.0 , trip.1) ).for_each( + |tup| all_positions.push( tup ) ) ; + } + all_positions.sort_by( |a , b| { + if a.0 != b.0 { + a.0.cmp( &b.0 ) + } + else { + a.1.cmp( &b.1 ) + }}) ; + all_positions +} + + +//once we have created an ordered list of positions , we remove the first element +//from the list of positions and store it in another vector. Then, we keep removing +//all those elements from the ordered list of positions that are neighbouring +//to any of the elements removed. If we don't find any such element, we store +//the number of elements in a size vector and return, once all original elements +//are used up, the maximum of this list +fn find_contiguous_blocks( positions : &mut Vec<(usize , usize)> ) -> usize { + let mut contiguous_blocksizes : Vec<usize> = Vec::new( ) ; + let mut contiguous_blocks : Vec<(usize , usize)> = Vec::new( ) ; + let pair : (usize , usize) = positions.remove( 0 ) ; + contiguous_blocks.push( pair ) ; + while positions.len( ) > 0 { + while let Some( pos ) = positions.iter( ).position( |&p| { + contiguous_blocks.iter( ).any( | pa | is_neighbouring( *pa , p ) ) + }) { + let elt : (usize , usize) = positions.remove( pos ) ; + contiguous_blocks.push( elt ) ; + } + contiguous_blocksizes.push( contiguous_blocks.len( ) ) ; + contiguous_blocks.clear( ) ; + if positions.len( ) > 0 { + let elt : (usize , usize ) = positions.remove( 0 ) ; + contiguous_blocks.push( elt ) ; + } + } + contiguous_blocksizes.into_iter( ).max( ).unwrap( ) +} + +fn is_neighbouring( first_pair : (usize, usize) , second_pair : (usize, usize) ) + -> bool { + (((first_pair.0 as i32) - ( second_pair.0 as i32)).abs( ) == 1 && + first_pair.1 == second_pair.1) || ( first_pair.0 == second_pair.0 ) && + (((first_pair.1 as i32) - (second_pair.1 as i32)).abs( ) == 1) +} + +fn main() -> io::Result<( )> { + println!("Enter some strings of equal length consisting of x and o!"); + println!("Enter <return> to end!" ) ; + let mut all_input : String = String::new( ) ; + let mut lines = io::stdin( ).lock( ).lines( ) ; + while let Some( line ) = lines.next( ) { + let last_input = line.unwrap( ) ; + if last_input.len( ) == 0 { + break ; + } + else { + all_input.push_str( &last_input ) ; + all_input.push_str( "\n" ) ; + } + } + let all_lines : &str = all_input.as_str( ).trim( ) ; + let rows : Vec<&str> = all_lines.split( "\n" ).collect( ) ; + let valid_rows : Vec<&str> = rows.into_iter( ).filter( | &s | + s.len( ) > 0 ).collect( ) ; + let mut x_blocks : Vec<(usize , usize)> = find_positions( &valid_rows , 'x' ) ; + let mut o_blocks : Vec<(usize , usize)> = find_positions( &valid_rows , 'o' ) ; + let x_maxfield : usize = find_contiguous_blocks( &mut x_blocks ) ; + let o_maxfield : usize = find_contiguous_blocks( &mut o_blocks ) ; + println!("{}" , cmp::max( x_maxfield , o_maxfield ) ) ; + Ok(()) +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 1c23c3bd8c..68b0f46b0a 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,13 +1,28 @@ { + "subtitle" : { + "text" : "[Champions: 24] Last updated at 2024-09-29 18:58:26 GMT" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "legend" : { + "enabled" : 0 + }, + "tooltip" : { + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "followPointer" : 1, + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>" + }, "series" : [ { "name" : "The Weekly Challenge - 288", - "colorByPoint" : 1, "data" : [ { "y" : 3, - "name" : "Andre Ploger", - "drilldown" : "Andre Ploger" + "drilldown" : "Andre Ploger", + "name" : "Andre Ploger" }, { "y" : 3, @@ -15,13 +30,18 @@ "drilldown" : "Arne Sommer" }, { + "name" : "Athanasius", + "drilldown" : "Athanasius", + "y" : 4 + }, + { + "y" : 2, "name" : "Dave Jacoby", - "drilldown" : "Dave Jacoby", - "y" : 2 + "drilldown" : "Dave Jacoby" }, { - "name" : "David Ferrone", "drilldown" : "David Ferrone", + "name" : "David Ferrone", "y" : 2 }, { @@ -36,8 +56,8 @@ }, { "y" : 3, - "drilldown" : "Jorg Sommrey", - "name" : "Jorg Sommrey" + "name" : "Jorg Sommrey", + "drilldown" : "Jorg Sommrey" }, { "y" : 2, @@ -46,13 +66,13 @@ }, { "y" : 3, - "name" : "Laurent Rosenfeld", - "drilldown" : "Laurent Rosenfeld" + "drilldown" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld" }, { - "drilldown" : "Lubos Kolouch", + "y" : 2, "name" : "Lubos Kolouch", - "y" : 2 + "drilldown" : "Lubos Kolouch" }, { "y" : 5, @@ -60,38 +80,48 @@ "drilldown" : "Luca Ferrari" }, { + "drilldown" : "Matthias Muth", + "name" : "Matthias Muth", + "y" : 3 + }, + { "y" : 5, - "drilldown" : "Packy Anderson", - "name" : "Packy Anderson" + "name" : "Packy Anderson", + "drilldown" : "Packy Anderson" }, { "y" : 2, - "name" : "Paulo Custodio", - "drilldown" : "Paulo Custodio" + "drilldown" : "Paulo Custodio", + "name" : "Paulo Custodio" }, { - "name" : "Peter Campbell Smith", + "y" : 3, "drilldown" : "Peter Campbell Smith", - "y" : 3 + "name" : "Peter Campbell Smith" }, { - "drilldown" : "Reinier Maliepaard", + "y" : 2, "name" : "Reinier Maliepaard", - "y" : 2 + "drilldown" : "Reinier Maliepaard" }, { + "y" : 3, "name" : "Robbie Hatley", - "drilldown" : "Robbie Hatley", - "y" : 3 + "drilldown" : "Robbie Hatley" }, { + "y" : 5, "name" : "Roger Bell_West", - "drilldown" : "Roger Bell_West", - "y" : 4 + "drilldown" : "Roger Bell_West" + }, + { + "y" : 2, + "name" : "Simon Green", + "drilldown" : "Simon Green" }, { - "name" : "Torgny Lyon", "drilldown" : "Torgny Lyon", + "name" : "Torgny Lyon", "y" : 3 }, { @@ -105,44 +135,23 @@ "name" : "W. Luis Mochan" }, { - "y" : 1, "drilldown" : "Wanderdoc", - "name" : "Wanderdoc" + "name" : "Wanderdoc", + "y" : 1 } - ] + ], + "colorByPoint" : 1 } ], "chart" : { "type" : "column" }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "legend" : { - "enabled" : 0 - }, - "tooltip" : { - "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/>", - "followPointer" : 1 - }, - "subtitle" : { - "text" : "[Champions: 21] Last updated at 2024-09-28 09:51:24 GMT" + "xAxis" : { + "type" : "category" }, "title" : { "text" : "The Weekly Challenge - 288" }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - }, - "borderWidth" : 0 - } - }, "drilldown" : { "series" : [ { @@ -170,10 +179,26 @@ 1 ] ], - "id" : "Arne Sommer", - "name" : "Arne Sommer" + "name" : "Arne Sommer", + "id" : "Arne Sommer" + }, + { + "id" : "Athanasius", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "name" : "Athanasius" }, { + "id" : "Dave Jacoby", + "name" : "Dave Jacoby", "data" : [ [ "Perl", @@ -183,23 +208,21 @@ "Blog", 1 ] - ], - "id" : "Dave Jacoby", - "name" : "Dave Jacoby" + ] }, { + "id" : "David Ferrone", "data" : [ [ "Perl", 2 ] ], - "id" : "David Ferrone", "name" : "David Ferrone" }, { - "name" : "E. Choroba", "id" : "E. Choroba", + "name" : "E. Choroba", "data" : [ [ "Perl", @@ -214,11 +237,10 @@ 2 ] ], - "id" : "Feng Chang", - "name" : "Feng Chang" + "name" : "Feng Chang", + "id" : "Feng Chang" }, { - "id" : "Jorg Sommrey", "name" : "Jorg Sommrey", "data" : [ [ @@ -229,7 +251,8 @@ "Blog", 1 ] - ] + ], + "id" : "Jorg Sommrey" }, { "id" : "Kjetil Skotheim", @@ -242,8 +265,6 @@ ] }, { - "id" : "Laurent Rosenfeld", - "name" : "Laurent Rosenfeld", "data" : [ [ "Perl", @@ -257,21 +278,21 @@ "Blog", 1 ] - ] + ], + "name" : "Laurent Rosenfeld", + "id" : "Laurent Rosenfeld" }, { + "id" : "Lubos Kolouch", "data" : [ [ "Perl", 2 ] ], - "id" : "Lubos Kolouch", "name" : "Lubos Kolouch" }, { - "name" : "Luca Ferrari", - "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -281,11 +302,27 @@ "Blog", 3 ] - ] + ], + "name" : "Luca Ferrari", + "id" : "Luca Ferrari" + }, + { + "id" : "Matthias Muth", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Matthias Muth" }, { - "name" : "Packy Anderson", "id" : "Packy Anderson", + "name" : "Packy Anderson", "data" : [ [ "Perl", @@ -302,16 +339,18 @@ ] }, { + "id" : "Paulo Custodio", + "name" : "Paulo Custodio", "data" : [ [ "Perl", 2 ] - ], - "name" : "Paulo Custodio", - "id" : "Paulo Custodio" + ] }, { + "id" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -321,12 +360,9 @@ "Blog", 1 ] - ], - "id" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + ] }, { - "id" : "Reinier Maliepaard", "name" : "Reinier Maliepaard", "data" : [ [ @@ -337,10 +373,10 @@ "Blog", 1 ] - ] + ], + "id" : "Reinier Maliepaard" }, { - "id" : "Robbie Hatley", "name" : "Robbie Hatley", "data" : [ [ @@ -351,11 +387,10 @@ "Blog", 1 ] - ] + ], + "id" : "Robbie Hatley" }, { - "id" : "Roger Bell_West", - "name" : "Roger Bell_West", "data" : [ [ "Perl", @@ -364,12 +399,28 @@ [ "Raku", 2 + ], + [ + "Blog", + 1 ] - ] + ], + "name" : "Roger Bell_West", + "id" : "Roger Bell_West" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Simon Green", + "id" : "Simon Green" }, { - "name" : "Torgny Lyon", "id" : "Torgny Lyon", + "name" : "Torgny Lyon", "data" : [ [ "Perl", @@ -382,6 +433,8 @@ ] }, { + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -391,11 +444,10 @@ "Raku", 1 ] - ], - "id" : "Ulrich Rieke", - "name" : "Ulrich Rieke" + ] }, { + "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -406,22 +458,27 @@ 1 ] ], - "id" : "W. Luis Mochan", "name" : "W. Luis Mochan" }, { + "id" : "Wanderdoc", "data" : [ [ "Perl", 1 ] ], - "name" : "Wanderdoc", - "id" : "Wanderdoc" + "name" : "Wanderdoc" } ] }, - "xAxis" : { - "type" : "category" + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 + } } } diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index fb0e41ebb8..1d95077552 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -1,17 +1,236 @@ { - "tooltip" : { - "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", - "headerFormat" : "<span style=\"font-size:11px\"></span>", - "followPointer" : "true" + "xAxis" : { + "type" : "category" }, - "legend" : { - "enabled" : "false" + "chart" : { + "type" : "column" }, - "title" : { - "text" : "The Weekly Challenge Language" + "series" : [ + { + "name" : "The Weekly Challenge Languages", + "data" : [ + { + "name" : "041", + "drilldown" : "041", + "y" : 80 + }, + { + "name" : "040", + "drilldown" : "040", + "y" : 77 + }, + { + "y" : 68, + "drilldown" : "039", + "name" : "039" + }, + { + "y" : 74, + "name" : "038", + "drilldown" : "038" + }, + { + "y" : 70, + "drilldown" : "037", + "name" : "037" + }, + { + "y" : 70, + "drilldown" : "036", + "name" : "036" + }, + { + "name" : "035", + "drilldown" : "035", + "y" : 68 + }, + { + "name" : "034", + "drilldown" : "034", + "y" : 70 + }, + { + "y" : 113, + "drilldown" : "033", + "name" : "033" + }, + { + "y" : 97, + "drilldown" : "032", + "name" : "032" + }, + { + "name" : "031", + "drilldown" : "031", + "y" : 93 + }, + { + "name" : "030", + "drilldown" : "030", + "y" : 120 + }, + { + "y" : 83, + "name" : "029", + "drilldown" : "029" + }, + { + "y" : 82, + "name" : "028", + "drilldown" : "028" + }, + { + "drilldown" : "027", + "name" : "027", + "y" : 64 + }, + { + "y" : 75, + "name" : "026", + "drilldown" : "026" + }, + { + "y" : 62, + "drilldown" : "025", + "name" : "025" + }, + { + "name" : "024", + "drilldown" : "024", + "y" : 77 + }, + { + "drilldown" : "023", + "name" : "023", + "y" : 88 + }, + { + "name" : "022", + "drilldown" : "022", + "y" : 72 + }, + { + "name" : "021", + "drilldown" : "021", + "y" : 72 + }, + { + "y" : 100, + "name" : "020", + "drilldown" : "020" + }, + { + "y" : 101, + "name" : "019", + "drilldown" : "019" + }, + { + "y" : 82, + "drilldown" : "018", + "name" : "018" + }, + { + "name" : "017", + "drilldown" : "017", + "y" : 83 + }, + { + "y" : 75, + "name" : "016", + "drilldown" : "016" + }, + { + "y" : 95, + "name" : "015", + "drilldown" : "015" + }, + { + "y" : 98, + "drilldown" : "014", + "name" : "014" + }, + { + "name" : "013", + "drilldown" : "013", + "y" : 85 + }, + { + "y" : 90, + "drilldown" : "012", + "name" : "012" + }, + { + "name" : "011", + "drilldown" : "011", + "y" : 86 + }, + { + "y" : 69, + "drilldown" : "010", + "name" : "010" + }, + { + "y" : 79, + "name" : "009", + "drilldown" : "009" + }, + { + "y" : 82, + "name" : "008", + "drilldown" : "008" + }, + { + "y" : 71, + "name" : "007", + "drilldown" : "007" + }, + { + "drilldown" : "006", + "name" : "006", + "y" : 63 + }, + { + "y" : 82, + "name" : "005", + "drilldown" : "005" + }, + { + "name" : "004", + "drilldown" : "004", + "y" : 106 + }, + { + "y" : 91, + "name" : "003", + "drilldown" : "003" + }, + { + "y" : 133, + "name" : "002", + "drilldown" : "002" + }, + { + "y" : 165, + "name" : "001", + "drilldown" : "001" + } + ], + "colorByPoint" : "true" + } + ], + "tooltip" : { + "followPointer" : "true", + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", + "headerFormat" : "<span style=\"font-size:11px\"></span>" }, - "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2024-09-28 09:51:24 GMT" + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } + } }, "drilldown" : { "series" : [ @@ -30,8 +249,8 @@ 9 ] ], - "id" : "041", - "name" : "041" + "name" : "041", + "id" : "041" }, { "id" : "040", @@ -71,7 +290,6 @@ }, { "name" : "038", - "id" : "038", "data" : [ [ "Perl", @@ -85,7 +303,8 @@ "Blog", 12 ] - ] + ], + "id" : "038" }, { "data" : [ @@ -106,6 +325,7 @@ "id" : "037" }, { + "id" : "036", "data" : [ [ "Perl", @@ -120,11 +340,9 @@ 11 ] ], - "id" : "036", "name" : "036" }, { - "name" : "035", "id" : "035", "data" : [ [ @@ -139,9 +357,12 @@ "Blog", 9 ] - ] + ], + "name" : "035" }, { + "id" : "034", + "name" : "034", "data" : [ [ "Perl", @@ -155,11 +376,11 @@ "Blog", 11 ] - ], - "name" : "034", - "id" : "034" + ] }, { + "id" : "033", + "name" : "033", "data" : [ [ "Perl", @@ -173,11 +394,10 @@ "Blog", 10 ] - ], - "name" : "033", - "id" : "033" + ] }, { + "id" : "032", "data" : [ [ "Perl", @@ -192,12 +412,10 @@ 10 ] ], - "id" : "032", "name" : "032" }, { "name" : "031", - "id" : "031", "data" : [ [ "Perl", @@ -211,7 +429,8 @@ "Blog", 9 ] - ] + ], + "id" : "031" }, { "id" : "030", @@ -232,6 +451,7 @@ ] }, { + "id" : "029", "data" : [ [ "Perl", @@ -246,10 +466,10 @@ 12 ] ], - "name" : "029", - "id" : "029" + "name" : "029" }, { + "id" : "028", "data" : [ [ "Perl", @@ -264,12 +484,10 @@ 9 ] ], - "id" : "028", "name" : "028" }, { "name" : "027", - "id" : "027", "data" : [ [ "Perl", |
