diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-09-01 19:04:44 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-09-01 19:04:44 +0100 |
| commit | d9f37544a8e230d1a709621961b5c564263cf01e (patch) | |
| tree | f523c455c18eb014f1d6622d6504fee9c22753cb | |
| parent | 07edc57d960e4022137eb3b2a211cb5b42c780a3 (diff) | |
| download | perlweeklychallenge-club-d9f37544a8e230d1a709621961b5c564263cf01e.tar.gz perlweeklychallenge-club-d9f37544a8e230d1a709621961b5c564263cf01e.tar.bz2 perlweeklychallenge-club-d9f37544a8e230d1a709621961b5c564263cf01e.zip | |
- Added solutions by Ulrich Rieke.
24 files changed, 1939 insertions, 1721 deletions
diff --git a/challenge-180/ulrich-rieke/cpp/ch-1.cpp b/challenge-180/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..58b6709590 --- /dev/null +++ b/challenge-180/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,25 @@ +#include <string> +#include <map> +#include <algorithm> +#include <iostream> +#include <vector> + +int main( ) { + std::cout << "Please enter a string!\n" ; + std::string input ; + getline( std::cin , input ) ; + std::map<std::string , int> frequencies ; + int len = input.length( ) ; + for ( int i = 0 ; i < len ; i++ ) { + frequencies[ input.substr( i , 1 )]++ ; + } + std::vector<int> findPositions ; + for ( const auto & p : frequencies ) { + if ( p.second == 1 ) { + findPositions.push_back( static_cast<int>( input.find( p.first ))) ; + } + } + std::cout << *std::min_element( findPositions.begin( ) , findPositions.end( ) ) << + std::endl ; + return 0 ; +} diff --git a/challenge-180/ulrich-rieke/cpp/ch-2.cpp b/challenge-180/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..0018bae00f --- /dev/null +++ b/challenge-180/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,25 @@ +#include <vector> +#include <iostream> +#include <iterator> +#include <algorithm> + +int main( ) { + std::vector<int> numbers ; + std::cout << "Enter an integer , -1 to end!\n" ; + int n ; + std::cin >> n ; + while ( n != -1 ) { + numbers.push_back( n ) ; + std::cout << "next integer!\n" ; + std::cin >> n ; + } + std::cout << "Enter a single integer!\n" ; + std::cin >> n ; + auto last = std::remove_if( numbers.begin( ) , numbers.end( ) , [n]( const int a ) + {return a <= n ; } ) ; + std::ostream_iterator<int> output( std::cout , " " ) ; + std::cout << "( " ; + std::copy( numbers.begin( ) , last , output ) ; + std::cout << ')' << std::endl ; + return 0 ; +} diff --git a/challenge-180/ulrich-rieke/haskell/ch-1.hs b/challenge-180/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..6c5e47a31d --- /dev/null +++ b/challenge-180/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,15 @@ +module Challenge180 + where +import Data.Char ( isSpace ) +import qualified Data.Set as S +import Data.List ( findIndices ) + +count :: Eq a => a -> [a] -> Int +count c [] = 0 +count d ( x:xs ) + |d == x = 1 + count d xs + |otherwise = count d xs + +solution :: String -> Int +solution s = minimum $ concat $ map (\c -> findIndices ( == c ) s ) $ +filter (\c -> count c s == 1 ) $ S.toList $ S.fromList s diff --git a/challenge-180/ulrich-rieke/haskell/ch-2.hs b/challenge-180/ulrich-rieke/haskell/ch-2.hs new file mode 100644 index 0000000000..775847369d --- /dev/null +++ b/challenge-180/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,14 @@ +{-# LANGUAGE ScopedTypeVariables #-} +module Challenge180_2 + where +import Data.List.Split ( splitOn ) + +main :: IO ( ) +main = do + putStrLn "Enter a number of integers, separated by a blank!" + numbers <- getLine + putStrLn "Enter a single integer!" + num <- getLine + let ( nums :: [Int] ) = map read $ splitOn " " numbers + (number :: Int ) = read num + print $ filter ( > number ) nums diff --git a/challenge-180/ulrich-rieke/perl/ch-1.pl b/challenge-180/ulrich-rieke/perl/ch-1.pl new file mode 100644 index 0000000000..983e36ff9c --- /dev/null +++ b/challenge-180/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +say "Enter a sentence!" ; +my $line = <STDIN> ; +chomp $line ; +my $len = length $line ; +my %letterFrequencies ; +for my $i ( 0 .. $len - 1 ) { + my $letter = substr( $line, $i , 1 ) ; + $letterFrequencies{$letter}++ ; +} +my @uniques = grep { $letterFrequencies{ $_ } == 1 } keys %letterFrequencies ; +my $minimumFound = $len ; +for my $letter ( @uniques ) { + my $found = index( $line , $letter ) ; + if ( $found < $minimumFound ) { + $minimumFound = $found ; + } +} +say $minimumFound ; diff --git a/challenge-180/ulrich-rieke/perl/ch-2.pl b/challenge-180/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..1de00110fc --- /dev/null +++ b/challenge-180/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +say "Enter some integers, separated by a blank!" ; +my $line = <STDIN> ; +chomp $line ; +while ( $line !~ /\A(\d+\s*)+\z/ ) { + say "Enter some integers and separate them with a blank!" ; + $line = <STDIN> ; + chomp $line ; +} +my @numbers = split( /\s+/ , $line ) ; +say "Enter an integer! " ; +$line = <STDIN> ; +chomp $line ; +say ( '(' . join( "," , grep { $_ > $line } @numbers ) . ')' ) ; diff --git a/challenge-180/ulrich-rieke/raku/ch-1.raku b/challenge-180/ulrich-rieke/raku/ch-1.raku new file mode 100644 index 0000000000..b4658832d8 --- /dev/null +++ b/challenge-180/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,20 @@ +use v6 ; + +say "Enter a sentence!" ; +my $line = $*IN.get ; +my %letterFrequencies ; +for (0 .. $line.chars - 1 ) -> $i { + my $letter = $line.substr( $i , 1 ) ; + if ( $letter ne " " ) { + %letterFrequencies{$letter}++ ; + } +} +my @uniques = %letterFrequencies.keys.grep( { %letterFrequencies{$_} == 1 } ) ; +my $minimumFound = $line.chars - 1 ; +for @uniques -> $letter { + my $found = $line.index( $letter ) ; + if ( $found < $minimumFound ) { + $minimumFound = $found ; + } +} +say $minimumFound ; diff --git a/challenge-180/ulrich-rieke/raku/ch-2.raku b/challenge-180/ulrich-rieke/raku/ch-2.raku new file mode 100644 index 0000000000..2623e105bb --- /dev/null +++ b/challenge-180/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,9 @@ +use v6 ; + +say "Enter a line of integers, separated by a blank!" ; +my $line = $*IN.get ; +my @numbers = $line.split( /\s+/ ).map( {.Int} ) ; +say "Enter an integer!" ; +$line = $*IN.get ; +my $number = +$line ; +say @numbers.grep( { $_ > $number} ) ; diff --git a/challenge-180/ulrich-rieke/rust/ch-1.rs b/challenge-180/ulrich-rieke/rust/ch-1.rs new file mode 100644 index 0000000000..47334c3207 --- /dev/null +++ b/challenge-180/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,32 @@ +use std::collections::HashMap ; +use std::collections::hash_map::Entry ; +use std::io ; + +fn main() { + let mut input = String::new( ) ; + let mut frequencies: HashMap<char , i32> = HashMap::new( ) ; + println!("Please enter a sentence!"); + io::stdin( ).read_line( &mut input).unwrap( ) ; + let entered_line: &mut str = &mut input[..] ; + for ch in entered_line.trim( ).chars( ) { + //we count the characters + *frequencies.entry( ch ).or_insert( 0 ) += 1 ; + } + //in find_pos we collect the positions where we find unique + //characters. We initialize the vector with the length + let mut find_pos: Vec<usize> = vec![entered_line.len( )] ; + for ch in entered_line.trim( ).chars( ) { + if let Entry::Occupied(o) = frequencies.entry( ch ) { + let num = o.get( ) ; + if *num == 1 { + find_pos.push( entered_line.find( ch ).unwrap( ) ) ; + } + } + } + let minimum = find_pos.iter( ).reduce( |accum , item| + if accum >= item { item } else { accum } ) ; + match minimum { + Some( a ) => println!("{}" , a ) , + None => {} + } ; +} diff --git a/challenge-180/ulrich-rieke/rust/ch-2.rs b/challenge-180/ulrich-rieke/rust/ch-2.rs new file mode 100644 index 0000000000..e1eced14c6 --- /dev/null +++ b/challenge-180/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,18 @@ +use std::io ; +fn main() { + println!("Please enter some integers, separated by a blank!" ) ; + let mut input = String::new( ) ; + io::stdin( ).read_line( &mut input ).unwrap( ) ; + let entered_line : &mut str = &mut input[..] ; + let nums: Vec<&str> = entered_line.split( " ").collect( ) ; + let numbers: Vec<u32> = nums.iter().map( |s| s.trim().parse( ) + .unwrap( ) ) .collect( ) ; + let mut number_input = String::new( ) ; + println!("Please enter an integer!") ; + io::stdin( ).read_line( &mut number_input).unwrap( ) ; + let number : &mut str = &mut number_input[..] ; + let num: u32 = number.trim( ).parse( ).unwrap( ) ; + let solution: Vec<u32> = numbers.iter( ).filter( |x| **x > num ) + .cloned().collect( ) ; + println!("{:?}" , solution); +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index da8a7e1b4b..c0940a2401 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,67 +1,216 @@ { + "legend" : { + "enabled" : 0 + }, + "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/>" + }, + "title" : { + "text" : "The Weekly Challenge - 180" + }, + "plotOptions" : { + "series" : { + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + }, + "borderWidth" : 0 + } + }, + "subtitle" : { + "text" : "[Champions: 21] Last updated at 2022-09-01 18:03:11 GMT" + }, + "xAxis" : { + "type" : "category" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "chart" : { + "type" : "column" + }, + "series" : [ + { + "name" : "The Weekly Challenge - 180", + "colorByPoint" : 1, + "data" : [ + { + "drilldown" : "Aut0exec", + "y" : 2, + "name" : "Aut0exec" + }, + { + "drilldown" : "Bejoy Mathews", + "y" : 2, + "name" : "Bejoy Mathews" + }, + { + "name" : "Ben Davies", + "y" : 2, + "drilldown" : "Ben Davies" + }, + { + "drilldown" : "Dave Jacoby", + "y" : 2, + "name" : "Dave Jacoby" + }, + { + "name" : "E. Choroba", + "y" : 2, + "drilldown" : "E. Choroba" + }, + { + "drilldown" : "Humberto Massa", + "name" : "Humberto Massa", + "y" : 2 + }, + { + "drilldown" : "James Smith", + "y" : 3, + "name" : "James Smith" + }, + { + "drilldown" : "Julien Fiegehenn", + "name" : "Julien Fiegehenn", + "y" : 1 + }, + { + "y" : 2, + "name" : "Kueppo Wesley", + "drilldown" : "Kueppo Wesley" + }, + { + "drilldown" : "Laurent Rosenfeld", + "y" : 5, + "name" : "Laurent Rosenfeld" + }, + { + "drilldown" : "Mark Anderson", + "y" : 2, + "name" : "Mark Anderson" + }, + { + "name" : "Marton Polgar", + "y" : 2, + "drilldown" : "Marton Polgar" + }, + { + "drilldown" : "Matthew Neleigh", + "name" : "Matthew Neleigh", + "y" : 2 + }, + { + "y" : 2, + "name" : "Niels van Dijke", + "drilldown" : "Niels van Dijke" + }, + { + "y" : 4, + "name" : "Robert DiCicco", + "drilldown" : "Robert DiCicco" + }, + { + "name" : "Roger Bell_West", + "y" : 5, + "drilldown" : "Roger Bell_West" + }, + { + "drilldown" : "Simon Proctor", + "name" : "Simon Proctor", + "y" : 2 + }, + { + "y" : 2, + "name" : "Solathian", + "drilldown" : "Solathian" + }, + { + "name" : "Stephen G Lynn", + "y" : 5, + "drilldown" : "Stephen G Lynn" + }, + { + "drilldown" : "Ulrich Rieke", + "y" : 4, + "name" : "Ulrich Rieke" + }, + { + "drilldown" : "W. Luis Mochan", + "y" : 3, + "name" : "W. Luis Mochan" + } + ] + } + ], "drilldown" : { "series" : [ { - "id" : "Aut0exec", - "name" : "Aut0exec", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Aut0exec", + "name" : "Aut0exec" }, { + "id" : "Bejoy Mathews", "name" : "Bejoy Mathews", "data" : [ [ "Perl", 2 ] - ], - "id" : "Bejoy Mathews" + ] }, { + "id" : "Ben Davies", + "name" : "Ben Davies", "data" : [ [ "Raku", 2 ] - ], - "name" : "Ben Davies", - "id" : "Ben Davies" + ] }, { - "id" : "Dave Jacoby", - "name" : "Dave Jacoby", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Dave Jacoby", + "name" : "Dave Jacoby" }, { + "name" : "E. Choroba", "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ], - "name" : "E. Choroba" + ] }, { - "id" : "Humberto Massa", "data" : [ [ "Raku", 2 ] ], + "id" : "Humberto Massa", "name" : "Humberto Massa" }, { + "name" : "James Smith", + "id" : "James Smith", "data" : [ [ "Perl", @@ -71,13 +220,11 @@ "Blog", 1 ] - ], - "name" : "James Smith", - "id" : "James Smith" + ] }, { - "id" : "Julien Fiegehenn", "name" : "Julien Fiegehenn", + "id" : "Julien Fiegehenn", "data" : [ [ "Perl", @@ -86,14 +233,14 @@ ] }, { - "id" : "Kueppo Wesley", - "name" : "Kueppo Wesley", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Kueppo Wesley", + "id" : "Kueppo Wesley" }, { "data" : [ @@ -114,8 +261,8 @@ "id" : "Laurent Rosenfeld" }, { - "id" : "Mark Anderson", "name" : "Mark Anderson", + "id" : "Mark Anderson", "data" : [ [ "Raku", @@ -124,36 +271,37 @@ ] }, { + "id" : "Marton Polgar", + "name" : "Marton Polgar", "data" : [ [ "Raku", 2 ] - ], - "name" : "Marton Polgar", - "id" : "Marton Polgar" + ] }, { + "id" : "Matthew Neleigh", "name" : "Matthew Neleigh", "data" : [ [ "Perl", 2 ] - ], - "id" : "Matthew Neleigh" + ] }, { + "name" : "Niels van Dijke", "id" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] - ], - "name" : "Niels van Dijke" + ] }, { + "id" : "Robert DiCicco", "name" : "Robert DiCicco", "data" : [ [ @@ -164,11 +312,9 @@ "Raku", 2 ] - ], - "id" : "Robert DiCicco" + ] }, { - "id" : "Roger Bell_West", "data" : [ [ "Perl", @@ -183,17 +329,18 @@ 1 ] ], + "id" : "Roger Bell_West", "name" : "Roger Bell_West" }, { + "id" : "Simon Proctor", "name" : "Simon Proctor", "data" : [ [ "Raku", 2 ] - ], - "id" : "Simon Proctor" + ] }, { "id" : "Solathian", @@ -206,6 +353,8 @@ ] }, { + "id" : "Stephen G Lynn", + "name" : "Stephen G Lynn", "data" : [ [ "Perl", @@ -219,9 +368,21 @@ "Blog", 1 ] - ], - "name" : "Stephen G Lynn", - "id" : "Stephen G Lynn" + ] + }, + { + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ] }, { "data" : [ @@ -234,151 +395,9 @@ 1 ] ], - "name" : "W. Luis Mochan", - "id" : "W. Luis Mochan" + "id" : "W. Luis Mochan", + "name" : "W. Luis Mochan" } ] - }, - "chart" : { - "type" : "column" - }, - "subtitle" : { - "text" : "[Champions: 20] Last updated at 2022-08-31 22:28:04 GMT" - }, - "series" : [ - { - "colorByPoint" : 1, - "data" : [ - { - "name" : "Aut0exec", - "drilldown" : "Aut0exec", - "y" : 2 - }, - { - "drilldown" : "Bejoy Mathews", - "name" : "Bejoy Mathews", - "y" : 2 - }, - { - "y" : 2, - "name" : "Ben Davies", - "drilldown" : "Ben Davies" - }, - { - "name" : "Dave Jacoby", - "drilldown" : "Dave Jacoby", - "y" : 2 - }, - { - "y" : 2, - "name" : "E. Choroba", - "drilldown" : "E. Choroba" - }, - { - "name" : "Humberto Massa", - "drilldown" : "Humberto Massa", - "y" : 2 - }, - { - "y" : 3, - "drilldown" : "James Smith", - "name" : "James Smith" - }, - { - "drilldown" : "Julien Fiegehenn", - "name" : "Julien Fiegehenn", - "y" : 1 - }, - { - "y" : 2, - "drilldown" : "Kueppo Wesley", - "name" : "Kueppo Wesley" - }, - { - "name" : "Laurent Rosenfeld", - "drilldown" : "Laurent Rosenfeld", - "y" : 5 - }, - { - "y" : 2, - "name" : "Mark Anderson", - "drilldown" : "Mark Anderson" - }, - { - "y" : 2, - "drilldown" : "Marton Polgar", - "name" : "Marton Polgar" - }, - { - "y" : 2, - "name" : "Matthew Neleigh", - "drilldown" : "Matthew Neleigh" - }, - { - "y" : 2, - "drilldown" : "Niels van Dijke", - "name" : "Niels van Dijke" - }, - { - "y" : 4, - "drilldown" : "Robert DiCicco", - "name" : "Robert DiCicco" - }, - { - "name" : "Roger Bell_West", - "drilldown" : "Roger Bell_West", - "y" : 5 - }, - { - "drilldown" : "Simon Proctor", - "name" : "Simon Proctor", - "y" : 2 - }, - { - "y" : 2, - "name" : "Solathian", - "drilldown" : "Solathian" - }, - { - "y" : 5, - "drilldown" : "Stephen G Lynn", - "name" : "Stephen G Lynn" - }, - { - "name" : "W. Luis Mochan", - "drilldown" : "W. Luis Mochan", - "y" : 3 - } - ], - "name" : "The Weekly Challenge - 180" - } - ], - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - }, - "borderWidth" : 0 - } - }, - "xAxis" : { - "type" : "category" - }, - "title" : { - "text" : "The Weekly Challenge - 180" - }, - "legend" : { - "enabled" : 0 - }, - "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/>" } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 9f0d4f865e..b5e82195f5 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,25 +1,36 @@ { + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2022]" + }, + "legend" : { + "enabled" : "false" + }, "subtitle" : { - "text" : "Last updated at 2022-08-31 22:28:04 GMT" + "text" : "Last updated at 2022-09-01 18:03:11 GMT" + }, + "xAxis" : { + "labels" : { + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + } + }, + "type" : "category" + }, + "yAxis" : { + "min" : 0, + "title" : { + "text" : null + } }, "chart" : { "type" : "column" }, "series" : [ { - "dataLabels" : { - "rotation" : -90, - "color" : "#FFFFFF", - "align" : "right", - "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" - }, - "y" : 10, - "enabled" : "true", - "format" : "{point.y:.0f}" - }, - "name" : "Contributions", "data" : [ [ "Blog", @@ -27,37 +38,26 @@ ], [ "Perl", - 8735 + 8737 ], [ "Raku", - 5223 + 5225 ] - ] - } - ], - "yAxis" : { - "title" : { - "text" : null - }, - "min" : 0 - }, - "xAxis" : { - "labels" : { - "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" + ], + "name" : "Contributions", + "dataLabels" : { + "enabled" : "true", + "y" : 10, + "align" : "right", + "rotation" : -90, + "color" : "#FFFFFF", + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + }, + "format" : "{point.y:.0f}" } - }, - "type" : "category" - }, - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2022]" - }, - "legend" : { - "enabled" : "false" - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - } + } + ] } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 4ec073b8c6..9926804b44 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,156 +1,163 @@ { + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "chart" : { + "type" : "column" + }, "series" : [ { - "name" : "The Weekly Challenge Languages", "data" : [ { "y" : 161, - "drilldown" : "001", - "name" : "#001" + "name" : "#001", + "drilldown" : "001" }, { + "name" : "#002", "y" : 125, - "drilldown" : "002", - "name" : "#002" + "drilldown" : "002" }, { - "name" : "#003", |
