diff options
25 files changed, 2787 insertions, 2469 deletions
diff --git a/challenge-215/ulrich-rieke/cpp/ch-1.cpp b/challenge-215/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..5f874934ed --- /dev/null +++ b/challenge-215/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,28 @@ +#include <iostream> +#include <string> +#include <vector> +#include <algorithm> + +std::vector<std::string> split( const std::string & startline , + const std::string & sep ) { + std::vector<std::string> separated ; + std::string::size_type start { 0 } ; + std::string::size_type pos ; + do { + pos = startline.find_first_of( sep , start ) ; + separated.push_back( startline.substr(start , pos - start )) ; + start = pos + 1 ; + } while ( pos != std::string::npos ) ; + return separated ; +} + +int main( ) { + std::cout << "Please enter some words, separated by blanks!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::vector<std::string> allStrings ( split( line , " " ) ) ; + std::cout << std::count_if( allStrings.begin( ) , allStrings.end( ) , + []( auto s ) { std::string c = s ; std::sort( c.begin( ) , + c.end( ) ) ; return c != s ; } ) << std::endl ; + return 0 ; +} diff --git a/challenge-215/ulrich-rieke/cpp/ch-2.cpp b/challenge-215/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..e6f54d4baa --- /dev/null +++ b/challenge-215/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,57 @@ +#include <iostream> +#include <string> +#include <algorithm> +#include <vector> + +std::vector<std::string> split( const std::string & startline , + const std::string & sep ) { + std::vector<std::string> separated ; + std::string::size_type start { 0 } ; + std::string::size_type pos ; + do { + pos = startline.find_first_of( sep , start ) ; + separated.push_back( startline.substr(start , pos - start )) ; + start = pos + 1 ; + } while ( pos != std::string::npos ) ; + return separated ; +} + +int main( ) { + std::cout << "Please enter a line of 1's and 0's, separated by blanks!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::vector<std::string> numberstrings( split( line, " " ) ) ; + std::vector<int> numbers ; + for ( auto s : numberstrings ) + numbers.push_back( std::stoi( s ) ) ; + std::cout << "How many 0's should be replaced ?\n" ; + int num ; + std::cin >> num ; + int necessary = 0 ; + if ( num == 1 ) + necessary = 3 ; + if ( num > 1 ) + necessary = 3 + num ; + int len = numbers.size( ) ; + if ( len < necessary || len == necessary ) + std::cout << 0 << std::endl ; + else { + std::vector<bool> results ; + for ( int start = 0 ; start < len - necessary + 1 ; start++ ) { + if ( std::all_of( numbers.begin( ) + start , numbers.begin( ) + start + + necessary , []( int n ) { return n == 0 ; } ) ) { + results.push_back( true ) ; + } + else + results.push_back( false ) ; + } + if ( std::any_of( results.begin( ) , results.end( ) , []( auto b ) { + return b == true ; })) { + std::cout << 1 << std::endl ; + } + else { + std::cout << 0 << std::endl ; + } + } + return 0 ; +} diff --git a/challenge-215/ulrich-rieke/haskell/ch-1.hs b/challenge-215/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..aa89e91420 --- /dev/null +++ b/challenge-215/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,16 @@ +module Challenge215 + where +import Data.List ( sort ) + +solution :: [String] -> Int +solution terms = length $ filter ( not . isSorted ) terms +where + isSorted :: String -> Bool + isSorted str = str == sort str + +main :: IO ( ) +main = do + putStrLn "Enter some words, separated by a blank!" + terms <- getLine + let theWords = words terms + print $ solution theWords diff --git a/challenge-215/ulrich-rieke/haskell/ch-2.hs b/challenge-215/ulrich-rieke/haskell/ch-2.hs new file mode 100644 index 0000000000..637e0382d8 --- /dev/null +++ b/challenge-215/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,27 @@ +module Challenge215_2 + where +import Data.List ( group ) + +solution :: [Int] -> Int -> Int +solution list zeroesToGo = if any(\li -> length li >= necessary && head li == 0 +) $ group list then 1 else 0 +where + necessary :: Int + necessary = if zeroesToGo == 1 then 3 else 3 + zeroesToGo + +condition :: [Int] -> Int -> Bool +condition list toGo = length list > necessary +where + necessary :: Int + necessary = if toGo == 1 then 3 else 3 + toGo + +main :: IO ( ) +main = do + putStrLn "Enter 1 and 0 , separated by a blank!" + line <- getLine + putStrLn "How many 0 should be removed ?" + toRemove <- getLine + let numbers = map read $ words line + kickout = read toRemove + if condition numbers kickout then print $ solution numbers kickout + else print 0 diff --git a/challenge-215/ulrich-rieke/perl/ch-1.pl b/challenge-215/ulrich-rieke/perl/ch-1.pl new file mode 100644 index 0000000000..2a6166152a --- /dev/null +++ b/challenge-215/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +sub is_sorted { + my $word = shift ; + my $sorted = join( '' , sort split( // , $word )) ; + return $sorted eq $word ; +} + +say "Enter some words, separated by blanks!" ; +my $line = <STDIN> ; +chomp $line ; +my @words = split( /\s/ , $line ) ; +say scalar( grep { not ( is_sorted( $_ ) ) } @words ) ; diff --git a/challenge-215/ulrich-rieke/perl/ch-2.pl b/challenge-215/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..923b3de999 --- /dev/null +++ b/challenge-215/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; +use List::Util qw ( all any ) ; + +say "Enter 1's and 0's, separated by a blank!" ; +my $line = <STDIN> ; +chomp $line ; +my @numbers = split( /\s/ , $line ) ; +say "Enter how many 0's are to be replaced!" ; +my $count = <STDIN> ; +chomp $count ; +#if we want to replace one 0 we have to have 3 in a row, if more than 1 , +#then 3 + 0 to be replaced +my $len = scalar( @numbers ) ; +my $necessary ; +if ( $count == 1 ) { + $necessary = 3 ; +} +if ( $count > 1 ) { + $necessary = 3 + $count ; +} +if ( $len < $necessary || $len == $necessary ) { + say 0 ; +} +else { + my @results ; + for my $i ( 0 .. $len - $necessary ) { + my @removed = splice( @numbers, $i , $necessary ) ; + if ( all { $_ == 0 } @removed ) { + push @results , 1 ; + } + else { + push @results, 0 ; + } + splice( @numbers, $i , $necessary, @removed ) ; + } + if ( any { $_ == 1 } @results ) { + say 1 ; + } + else { + say 0 ; + } +} diff --git a/challenge-215/ulrich-rieke/raku/ch-1.raku b/challenge-215/ulrich-rieke/raku/ch-1.raku new file mode 100644 index 0000000000..6777d913c3 --- /dev/null +++ b/challenge-215/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,11 @@ +use v6 ; + +sub is_sorted( $aWord ) { + my $sorted = $aWord.comb.sort.join ; + return $sorted eq $aWord ; +} + +say "Enter some words, separated by blanks!" ; +my $line = $*IN.get ; +my @words = $line.words ; +say @words.grep( { not ( is_sorted( $_ ) ) } ).elems ; diff --git a/challenge-215/ulrich-rieke/raku/ch-2.raku b/challenge-215/ulrich-rieke/raku/ch-2.raku new file mode 100644 index 0000000000..8b4c1506b7 --- /dev/null +++ b/challenge-215/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,38 @@ +use v6 ; + +say "Enter only 1's and 0's in a row, separated by blanks!" ; +my $line = $*IN.get ; +my @numbers = $line.words.map( {.Int} ) ; +say "How many zeroes would you like to replace?" ; +my $count = $*IN.get.Int ; +my $len = @numbers.elems ; +my $necessary_row ; +if ( $count = 1 ) { + $necessary_row = 3 ; +} +if ( $count > 1 ) { + $necessary_row = 3 + $count ; +} +if ( $len < $necessary_row || $len == $necessary_row ) { + say 0 ; +} +else { + my @results ; + for (0..$len - $necessary_row ) -> $i { + my @removed = @numbers.splice($i , $necessary_row) ; + if ( @removed.grep( {$_ == 0} ).elems == @removed.elems ) { + @results.push( True ) ; + } + else { + @results.push( False ) ; + } + splice( @numbers , $i , $necessary_row , @removed ) ; + say @numbers.join( ',' ) ; + } + if (any(@results) == True ) { + say 1 ; + } + else { + say 0 ; + } +} diff --git a/challenge-215/ulrich-rieke/rust/ch-1.rs b/challenge-215/ulrich-rieke/rust/ch-1.rs new file mode 100644 index 0000000000..47a72432fe --- /dev/null +++ b/challenge-215/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,22 @@ +use std::io ; + +fn is_sorted( word : &str ) -> bool { + let mut word_letters : Vec<char> = Vec::new( ) ; + for c in word.chars( ) { + word_letters.push( c ) ; + } + let mut compared_to : Vec<char> = word_letters.clone( ) ; + compared_to.sort( ) ; + compared_to == word_letters +} + +fn main() { + println!("Enter some words, separated by a blank!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = &*inline ; + let words : Vec<&str> = entered_line.split_whitespace( ).map( | s | + s.trim( ) ).collect( ) ; + println!( "{}" , words.iter( ).filter( | s | ! is_sorted( *s ) ). + count( ) ) ; +} diff --git a/challenge-215/ulrich-rieke/rust/ch-2.rs b/challenge-215/ulrich-rieke/rust/ch-2.rs new file mode 100644 index 0000000000..813397a4ab --- /dev/null +++ b/challenge-215/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,39 @@ +use std::io ; + +fn main() { + println!("Enter 1 and 0 only!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = &*inline ; + let numbers : Vec<usize> = entered_line.split_whitespace( ).map( | s | + s.trim( ).parse::<usize>( ).unwrap( )).collect( ) ; + println!("How many 0's should be replaced ?") ; + let mut secondline : String = String::new( ) ; + io::stdin( ).read_line( &mut secondline ).unwrap( ) ; + //the basic idea is : to replace n zeroes you have to have 3 zeroes in + //a row if n is 1, 3 + ( number to replace ) otherwise + let zerocount : usize = secondline.trim( ).parse::<usize>( ).unwrap( ) ; + let necessary_row = match zerocount { + 0 => 0 , + 1 => 3 , + _ => 3 + zerocount + } ; + let len = numbers.len( ) ; + if len < necessary_row || len == necessary_row { + println!("0") ; + } + else { + let mut conditions : Vec<bool> = Vec::new( ) ; + for i in 0..=(len - necessary_row) { + let sub_slice = &numbers[i..i + necessary_row] ; + let mut slice_iter = sub_slice.iter( ) ; + conditions.push( slice_iter.all( | n | *n == 0 )) ; + } + if conditions.iter( ).any( | c | *c == true ) { + println!("1") ; + } + else { + println!("0") ; + } + } +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 1010f533fb..1739b90695 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,61 +1,129 @@ { - "title" : { - "text" : "The Weekly Challenge - 215" - }, + "series" : [ + { + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 215", + "data" : [ + { + "drilldown" : "Carlos Oliveira", + "y" : 2, + "name" : "Carlos Oliveira" + }, + { + "drilldown" : "David Ferrone", + "y" : 2, + "name" : "David Ferrone" + }, + { + "y" : 2, + "drilldown" : "E. Choroba", + "name" : "E. Choroba" + }, + { + "drilldown" : "James Smith", + "y" : 3, + "name" : "James Smith" + }, + { + "y" : 2, + "drilldown" : "Lubos Kolouch", + "name" : "Lubos Kolouch" + }, + { + "name" : "Mark Anderson", + "y" : 2, + "drilldown" : "Mark Anderson" + }, + { + "name" : "Niels van Dijke", + "drilldown" : "Niels van Dijke", + "y" : 2 + }, + { + "drilldown" : "Peter Campbell Smith", + "y" : 3, + "name" : "Peter Campbell Smith" + }, + { + "name" : "Robert DiCicco", + "drilldown" : "Robert DiCicco", + "y" : 2 + }, + { + "drilldown" : "Stephen G. Lynn", + "y" : 2, + "name" : "Stephen G. Lynn" + }, + { + "y" : 4, + "drilldown" : "Thomas Kohler", + "name" : "Thomas Kohler" + }, + { + "name" : "Ulrich Rieke", + "y" : 4, + "drilldown" : "Ulrich Rieke" + }, + { + "name" : "W. Luis Mochan", + "drilldown" : "W. Luis Mochan", + "y" : 3 + } + ] + } + ], "plotOptions" : { "series" : { "borderWidth" : 0, "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" + "format" : "{point.y}", + "enabled" : 1 } } }, + "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/>" + }, "xAxis" : { "type" : "category" }, - "chart" : { - "type" : "column" - }, - "legend" : { - "enabled" : 0 - }, - "subtitle" : { - "text" : "[Champions: 12] Last updated at 2023-05-02 18:08:30 GMT" - }, "drilldown" : { "series" : [ { "id" : "Carlos Oliveira", - "name" : "Carlos Oliveira", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Carlos Oliveira" }, { + "id" : "David Ferrone", "data" : [ [ "Perl", 2 ] ], - "id" : "David Ferrone", "name" : "David Ferrone" }, { - "id" : "E. Choroba", "name" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "E. Choroba" }, { + "id" : "James Smith", + "name" : "James Smith", "data" : [ [ "Perl", @@ -65,39 +133,37 @@ "Blog", 1 ] - ], - "id" : "James Smith", - "name" : "James Smith" + ] }, { + "id" : "Lubos Kolouch", "data" : [ [ "Perl", 2 ] ], - "id" : "Lubos Kolouch", "name" : "Lubos Kolouch" }, { + "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] ], - "id" : "Mark Anderson", - "name" : "Mark Anderson" + "id" : "Mark Anderson" }, { - "name" : "Niels van Dijke", - "id" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Niels van Dijke", + "id" : "Niels van Dijke" }, { "data" : [ @@ -110,10 +176,12 @@ 1 ] ], - "id" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith" }, { + "id" : "Robert DiCicco", + "name" : "Robert DiCicco", "data" : [ [ "Perl", @@ -123,21 +191,20 @@ "Raku", 1 ] - ], - "name" : "Robert DiCicco", - "id" : "Robert DiCicco" + ] }, { + "id" : "Stephen G. Lynn", + "name" : "Stephen G. Lynn", "data" : [ [ "Perl", 2 ] - ], - "name" : "Stephen G. Lynn", - "id" : "Stephen G. Lynn" + ] }, { + "id" : "Thomas Kohler", "data" : [ [ "Perl", @@ -148,12 +215,24 @@ 2 ] ], - "name" : "Thomas Kohler", - "id" : "Thomas Kohler" + "name" : "Thomas Kohler" + }, + { + "name" : "Ulrich Rieke", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Ulrich Rieke" }, { "name" : "W. Luis Mochan", - "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -163,86 +242,26 @@ "Blog", 1 ] - ] + ], + "id" : "W. Luis Mochan" } ] }, - "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/>" + "chart" : { + "type" : "column" }, "yAxis" : { "title" : { "text" : "Total Solutions" } }, - "series" : [ - { - "name" : "The Weekly Challenge - 215", - "colorByPoint" : 1, - "data" : [ - { - "y" : 2, - "drilldown" : "Carlos Oliveira", - "name" : "Carlos Oliveira" - }, - { - "drilldown" : "David Ferrone", - "name" : "David Ferrone", - "y" : 2 - }, - { - "y" : 2, - "name" : "E. Choroba", - "drilldown" : "E. Choroba" - }, - { - "y" : 3, - "name" : "James Smith", - "drilldown" : "James Smith" - }, - { - "drilldown" : "Lubos Kolouch", - "name" : "Lubos Kolouch", - "y" : 2 - }, - { - "y" : 2, - "drilldown" : "Mark Anderson", - "name" : "Mark Anderson" - }, - { - "drilldown" : "Niels van Dijke", - "name" : "Niels van Dijke", - "y" : 2 - }, - { - "name" : "Peter Campbell Smith", - "drilldown" : "Peter Campbell Smith", - "y" : 3 - }, - { - "y" : 2, - "name" : "Robert DiCicco", - "drilldown" : "Robert DiCicco" - }, - { - "name" : "Stephen G. Lynn", - "drilldown" : "Stephen G. Lynn", - "y" : 2 - }, - { - "y" : 4, - "name" : "Thomas Kohler", - "drilldown" : "Thomas Kohler" - }, - { - "y" : 3, - "drilldown" : "W. Luis Mochan", - "name" : "W. Luis Mochan" - } - ] - } - ] + "legend" : { + "enabled" : 0 + }, + "subtitle" : { + "text" : "[Champions: 13] Last updated at 2023-05-02 18:32:18 GMT" + }, + "title" : { + "text" : "The Weekly Challenge - 215" + } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 4369454ef9..96d318e532 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,18 +1,39 @@ { + "legend" : { + "enabled" : "false" + }, + "chart" : { + "type" : "column" + }, + "yAxis" : { + "title" : { + "text" : null + }, + "min" : 0 + }, + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2023]" + }, + "subtitle" : { + "text" : "Last updated at 2023-05-02 18:32:18 GMT" + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, "series" : [ { "name" : "Contributions", "dataLabels" : { "y" : 10, - "rotation" : -90, - "format" : "{point.y:.0f}", "color" : "#FFFFFF", + "align" : "right", + "enabled" : "true", "style" : { "fontFamily" : "Verdana, sans-serif", "fontSize" : "13px" }, - "enabled" : "true", - "align" : "right" + "format" : "{point.y:.0f}", + "rotation" : -90 }, "data" : [ [ @@ -21,43 +42,22 @@ ], [ "Perl", - 10919 + 10921 ], [ "Raku", - 6325 + 6327 ] ] } ], - "yAxis" : { - "title" : { - "text" : null - }, - "min" : 0 - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, - "subtitle" : { - "text" : "Last updated at 2023-05-02 18:08:30 GMT" - }, - "chart" : { - "type" : "column" - }, - "legend" : { - "enabled" : "false" - }, "xAxis" : { + "type" : "category", "labels" : { "style" : { "fontSize" : "13px", "fontFamily" : "Verdana, sans-serif" } - }, - "type" : "category" - }, - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2023]" + } } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 5dec8c590b..0734fd110f 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,1124 +1,8 @@ { - "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/>" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "series" : [ - { - "data" : [ - { - "y" : 163, - "drilldown" : "001", - "name" : "#001" - }, - { - "name" : "#002", - "drilldown" : "002", - "y" : 129 - }, - { - "y" : 87, - "name" : "#003", - "drilldown" : "003" - }, - { - "drilldown" : "004", - "name" : "#004", - "y" : 103 - }, - { - "y" : 80, - "drilldown" : "005", - "name" : "#005" - }, - { - "name" : "#006", - "drilldown" : "006", - "y" : 61 - }, - { - "y" : 69, - "name" : "#007", - "drilldown" : "007" - }, - { - "y" : 82, - "name" : "#008", - "drilldown" : "008" - }, - { - "name" : "#009", - "drilldown" : "009", - "y" : 80 - }, - { - "name" : "#010", - "drilldown" : "010", - "y" : 69 - }, - { - "name" : "#011", - "drilldown" : "011", - "y" : 89 - }, - { - "name" : "#012", - "drilldown" : "012", - "y" : 92 - }, - { - "name" : "#013", - "drilldown" : "013", - "y" : 87 - }, - { - "drilldown" : "014", - "name" : "#014", - "y" : 102 - }, - { - "drilldown" : "015", - "name" : "#015", - "y" : 101 - }, - { - "y" : 72, - "name" : "#016", - "drilldown" : "016" - }, - { - "drilldown" : "017", - "name" : "#017", - "y" : 86 - }, - { - "drilldown" : "018", - "name" : "#018", - "y" : 83 - }, - { - "name" : "#019", - "drilldown" : "019", - "y" : 105 - }, - { - "name" : "#020", - "drilldown" : "020", - "y" : 103 - }, - { - "y" : 74, - "drilldown" : "021", - "name" : "#021" - }, - { - "y" : 72, - "name" : "#022", - "drilldown" : "022" - }, - { - "y" : 101, - "name" : "#023", - "drilldown" : "023" - }, - { - "drilldown" : "024", - "name" : "#024", - "y" : 77 - }, - { - "drilldown" : "025", - "name" : "#025", - "y" : 62 - }, - { - "drilldown" : "026", - "name" : "#026", - "y" : 76 - }, - { |
