diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-03-25 00:02:23 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-03-25 00:02:23 +0000 |
| commit | 99f7d0df506e8b6e8aa200532a125a43d5f38744 (patch) | |
| tree | 2730a1107500cb29046ec434642481f3de0dcc86 | |
| parent | bd47dfc5c29c45cb2fcb8069756ed74921690644 (diff) | |
| download | perlweeklychallenge-club-99f7d0df506e8b6e8aa200532a125a43d5f38744.tar.gz perlweeklychallenge-club-99f7d0df506e8b6e8aa200532a125a43d5f38744.tar.bz2 perlweeklychallenge-club-99f7d0df506e8b6e8aa200532a125a43d5f38744.zip | |
- Added solutions by Ulrich Rieke.
23 files changed, 1680 insertions, 1496 deletions
diff --git a/challenge-105/ulrich-rieke/cpp/ch-1.cpp b/challenge-105/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..bccb9fe7fd --- /dev/null +++ b/challenge-105/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,16 @@ +#include <iostream> +#include <cmath> +#include <cstdlib> + +int main( int argc, char * argv[ ] ) { + if ( argc != 3 ) { + std::cerr << "Error! usage <challenge105> <inversed root> <number>!\n" ; + return 1 ; + } + int n = std::atoi( argv[ 1 ] ) ; + int k = std::atoi( argv[ 2 ] ) ; + double d = std::pow( static_cast<double>( k ) , + (static_cast<double>( 1 ) / static_cast<double>( n ) ) ) ; + std::cout << d << std::endl ; + return 0 ; +} diff --git a/challenge-105/ulrich-rieke/cpp/ch-2.cpp b/challenge-105/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..9407d1b3f7 --- /dev/null +++ b/challenge-105/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,37 @@ +#include <iostream> +#include <string> +#include <vector> +#include <regex> +#include <cstring> + +int main( int argc, char* argv[] ) { + std::string name { argv[ 1 ] } ; + std::string affixed ; + std::vector<std::string> components {"bo-b" , "Bonana-fanna fo-f" , "Fee fi mo-m" } ; + std::regex vowels {"[AEIOU]"} ; + std::regex consonants { "[BFM]" } ; + std::string firstLetter { name.substr( 0 , 1 ) } ; + if ( std::regex_match( firstLetter , vowels )) { + affixed = name ; + for ( auto & c : affixed ) + c = std::tolower( c ) ; + } + else { + if ( std::regex_match( firstLetter, consonants ) ) { + char compareLetter { static_cast<char>(std::tolower ( name[ 0 ] )) } ; + for ( auto & s: components ) { + if ( s.back( ) == compareLetter ) { + s = s.substr( 0 , s.length( ) - 1 ) ; + } + } + } + affixed = name.substr( 1 ) ; + } + std::cout << name << ", " << name << ' ' << *(components.begin( )) << + affixed << '\n' ; + for ( int i = 1 ; i < 3 ; i++ ) { + std::cout << *(components.begin( ) + i ) << affixed << '\n' ; + } + std::cout << name << "!\n" ; + return 0 ; +} diff --git a/challenge-105/ulrich-rieke/haskell/ch-1.hs b/challenge-105/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..c969f3494e --- /dev/null +++ b/challenge-105/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,5 @@ +module Challenge105 + where + +solution :: Int -> Int -> Float +solution n k = (fromIntegral k) ** ((fromIntegral 1) / (fromIntegral n)) diff --git a/challenge-105/ulrich-rieke/haskell/ch-2.hs b/challenge-105/ulrich-rieke/haskell/ch-2.hs new file mode 100644 index 0000000000..358bf6c962 --- /dev/null +++ b/challenge-105/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,30 @@ +module Challenge105_2 + where +import Data.Char ( toLower ) +import Data.List ((!!)) + +rhymes :: [String] +rhymes = ["bo-b" , "Bonana-fanna fo-f" , "Fee fi mo-m"] + +isVowel :: Char -> Bool +isVowel c = elem c "aeiou" + +isCritical :: Char -> Bool +isCritical c = elem c "bfm" + +solution :: String -> [String] +solution name = [name ++ ", " ++ name ++ ", " ++ (convert (rhymes !! 0 ) ), +convert ( rhymes !! 1 ) , convert ( rhymes !! 2 ) , name ++ "!" ] +where + start :: Char + start = head name + convert :: String -> String + convert s + |isVowel $ toLower start = s ++ [toLower start] ++ tail name + |isCritical $ toLower start = if (toLower start) == last s + then init s ++ tail name else s ++ tail name + |otherwise = s ++ tail name + +main :: String -> IO ( ) +main name = do + mapM_ putStrLn $ solution name diff --git a/challenge-105/ulrich-rieke/java/Challenge105.java b/challenge-105/ulrich-rieke/java/Challenge105.java new file mode 100644 index 0000000000..676cf297ec --- /dev/null +++ b/challenge-105/ulrich-rieke/java/Challenge105.java @@ -0,0 +1,8 @@ +public class Challenge105 { + public static void main( String[] args ) { + double rootnum = Double.parseDouble( args[0]) ; + double fromNumber = Double.parseDouble(args[1]) ; + double result = Math.pow( fromNumber , 1 / rootnum ) ; + System.out.println( result ) ; + } +} diff --git a/challenge-105/ulrich-rieke/lisp/ch-1.lisp b/challenge-105/ulrich-rieke/lisp/ch-1.lisp new file mode 100644 index 0000000000..f012cfe7d0 --- /dev/null +++ b/challenge-105/ulrich-rieke/lisp/ch-1.lisp @@ -0,0 +1,5 @@ +#!/usr/bin/sbcl --script +(defun myRoot (n k ) +(expt k (/ 1 n))) + +(format t "~f~%" (myRoot 5 34)) diff --git a/challenge-105/ulrich-rieke/perl/ch-1.pl b/challenge-105/ulrich-rieke/perl/ch-1.pl new file mode 100644 index 0000000000..22756f90ad --- /dev/null +++ b/challenge-105/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,9 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +die "2 arguments required!" unless ( @ARGV == 2 ) ; +my $N = $ARGV[0] ; +my $k = $ARGV[1] ; +say $k ** (1 / $N ) ; diff --git a/challenge-105/ulrich-rieke/perl/ch-2.pl b/challenge-105/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..5f910ec919 --- /dev/null +++ b/challenge-105/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +my $name = $ARGV[ 0 ] ; +my $y ; #has to be affixed to the rhyme +my @components = ("bo-b" , "Bonana-fanna fo-f" , "Fee fi mo-m" ) ; +if ( lc( substr( $name , 0 , 1 )) =~ /[aeiou]/ ) { + $y = lc $name ; +} +else { + if ( lc( substr( $name , 0 , 1 )) =~ /[bfm]/ ) { + my $firstLetter = lc ( substr( $name, 0 , 1 ) ) ; + for my $rhyme ( @components ) { + my $len = length $rhyme ; + if ( substr( $rhyme , $len - 1 , 1 ) eq $firstLetter ) { + $rhyme = substr( $rhyme, 0 , $len - 1 ) ; + } + } + } + $y = substr( $name , 1 ) ; +} +say "$name, $name, $components[0]$y" ; +map { say "$_$y" } @components[1..2] ; +say "$name!" ; diff --git a/challenge-105/ulrich-rieke/raku/ch-1.raku b/challenge-105/ulrich-rieke/raku/ch-1.raku new file mode 100644 index 0000000000..a903072c02 --- /dev/null +++ b/challenge-105/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,5 @@ +use v6 ; + +sub MAIN( Int $root , Int $number ) { + say (1 / $root).exp( $number ) ; +} diff --git a/challenge-105/ulrich-rieke/raku/ch-2.raku b/challenge-105/ulrich-rieke/raku/ch-2.raku new file mode 100644 index 0000000000..3ccd07264e --- /dev/null +++ b/challenge-105/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,24 @@ +use v6 ; + +sub MAIN( Str $name ) { + my $y ; #the string to be affixed to the rhyme + my @components = ("bo-b" , "Bonana-fanna fo-f" , "Fee fi mo-m" ) ; + if ( $name.substr(0 , 1).lc ~~ /<[aeiou]>/ ) { + $y = $name.lc ; + } + else { + if ( $name.substr( 0 , 1 ).lc ~~ /<[bfm]>/ ) { + my $firstLetter = $name.substr( 0 , 1 ).lc ; + for @components <-> $rhyme { + my $len = $rhyme.chars ; + if ( $rhyme.substr( $len - 1 , 1 ) eq $firstLetter ) { + $rhyme = $rhyme.substr(0 , $len - 1 ) ; + } + } + } + $y = $name.substr( 1 ) ; + } + say "$name, $name , {@components[0]}$y" ; + @components[1..2].map( { say "$_$y" } ) ; + say "$name!" ; +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index f6fa630bcf..649f5d6fd7 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,24 +1,16 @@ { - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "legend" : { - "enabled" : 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/>" + "subtitle" : { + "text" : "[Champions: 10] Last updated at 2021-03-25 00:02:09 GMT" }, "series" : [ { + "colorByPoint" : 1, + "name" : "Perl Weekly Challenge - 105", "data" : [ { - "y" : 2, "drilldown" : "Abigail", - "name" : "Abigail" + "name" : "Abigail", + "y" : 2 }, { "y" : 3, @@ -26,9 +18,9 @@ "drilldown" : "Dave Jacoby" }, { - "drilldown" : "E. Choroba", + "y" : 2, "name" : "E. Choroba", - "y" : 2 + "drilldown" : "E. Choroba" }, { "y" : 2, @@ -36,40 +28,40 @@ "drilldown" : "James Smith" }, { + "y" : 4, "name" : "Luca Ferrari", - "drilldown" : "Luca Ferrari", - "y" : 4 + "drilldown" : "Luca Ferrari" }, { - "y" : 2, + "name" : "Mark Anderson", "drilldown" : "Mark Anderson", - "name" : "Mark Anderson" + "y" : 2 }, { "y" : 2, - "name" : "Paulo Custodio", - "drilldown" : "Paulo Custodio" + "drilldown" : "Paulo Custodio", + "name" : "Paulo Custodio" }, { + "y" : 4, "drilldown" : "Roger Bell_West", - "name" : "Roger Bell_West", + "name" : "Roger Bell_West" + }, + { + "name" : "Stuart Little", + "drilldown" : "Stuart Little", "y" : 4 }, { "y" : 4, - "drilldown" : "Stuart Little", - "name" : "Stuart Little" + "name" : "Ulrich Rieke", + "drilldown" : "Ulrich Rieke" } - ], - "colorByPoint" : 1, - "name" : "Perl Weekly Challenge - 105" + ] } ], - "chart" : { - "type" : "column" - }, - "xAxis" : { - "type" : "category" + "title" : { + "text" : "Perl Weekly Challenge - 105" }, "drilldown" : { "series" : [ @@ -80,8 +72,8 @@ 2 ] ], - "id" : "Abigail", - "name" : "Abigail" + "name" : "Abigail", + "id" : "Abigail" }, { "data" : [ @@ -109,17 +101,15 @@ }, { "id" : "James Smith", - "name" : "James Smith", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "James Smith" }, { - "name" : "Luca Ferrari", - "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -129,29 +119,33 @@ "Blog", 2 ] - ] + ], + "name" : "Luca Ferrari", + "id" : "Luca Ferrari" }, { + "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] ], - "id" : "Mark Anderson", - "name" : "Mark Anderson" + "id" : "Mark Anderson" }, { + "name" : "Paulo Custodio", "data" : [ [ "Perl", 2 ] ], - "id" : "Paulo Custodio", - "name" : "Paulo Custodio" + "id" : "Paulo Custodio" }, { + "id" : "Roger Bell_West", + "name" : "Roger Bell_West", "data" : [ [ "Perl", @@ -161,13 +155,23 @@ "Raku", 2 ] - ], - "name" : "Roger Bell_West", - "id" : "Roger Bell_West" + ] }, { - "id" : "Stuart Little", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], "name" : "Stuart Little", + "id" : "Stuart Little" + }, + { "data" : [ [ "Perl", @@ -177,23 +181,38 @@ "Raku", 2 ] - ] + ], + "name" : "Ulrich Rieke", + "id" : "Ulrich Rieke" } ] }, - "title" : { - "text" : "Perl Weekly Challenge - 105" + "chart" : { + "type" : "column" }, "plotOptions" : { "series" : { - "borderWidth" : 0, "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - } + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 } }, - "subtitle" : { - "text" : "[Champions: 9] Last updated at 2021-03-24 23:16:28 GMT" + "legend" : { + "enabled" : 0 + }, + "xAxis" : { + "type" : "category" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "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/>" } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index a0aac810ad..5cbe670e03 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,33 +1,25 @@ { - "subtitle" : { - "text" : "Last updated at 2021-03-24 23:16:28 GMT" - }, - "xAxis" : { - "labels" : { - "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" - } - }, - "type" : "category" - }, "title" : { "text" : "Perl Weekly Challenge Contributions [2019 - 2020]" }, - "chart" : { - "type" : "column" - }, - "yAxis" : { - "min" : 0, - "title" : { - "text" : null - } - }, - "legend" : { - "enabled" : "false" + "subtitle" : { + "text" : "Last updated at 2021-03-25 00:02:09 GMT" }, "series" : [ { + "dataLabels" : { + "align" : "right", + "rotation" : -90, + "y" : 10, + "enabled" : "true", + "format" : "{point.y:.0f}", + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + }, + "color" : "#FFFFFF" + }, + "name" : "Contributions", "data" : [ [ "Blog", @@ -35,29 +27,37 @@ ], [ "Perl", - 4928 + 4930 ], [ "Raku", - 3148 + 3150 ] - ], - "dataLabels" : { - "align" : "right", - "enabled" : "true", - "color" : "#FFFFFF", - "rotation" : -90, - "y" : 10, - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - }, - "format" : "{point.y:.0f}" - }, - "name" : "Contributions" + ] } ], + "chart" : { + "type" : "column" + }, + "legend" : { + "enabled" : "false" + }, + "xAxis" : { + "type" : "category", + "labels" : { + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + } + } + }, "tooltip" : { "pointFormat" : "<b>{point.y:.0f}</b>" + }, + "yAxis" : { + "title" : { + "text" : null + }, + "min" : 0 } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 3491434acb..41a989a04e 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,15 +1,7 @@ { - "xAxis" : { - "type" : "category" - }, - "title" : { - "text" : "Perl Weekly Challenge Language" - }, "drilldown" : { "series" : [ { - "id" : "001", - "name" : "001", "data" : [ [ "Perl", @@ -23,11 +15,12 @@ "Blog", 11 ] - ] + ], + "name" : "001", + "id" : "001" }, { "name" : "002", - "id" : "002", "data" : [ [ "Perl", @@ -41,11 +34,10 @@ "Blog", 10 ] - ] + ], + "id" : "002" }, { - "name" : "003", - "id" : "003", "data" : [ [ "Perl", @@ -59,11 +51,12 @@ "Blog", 9 ] - ] + ], + "name" : "003", + "id" : "003" }, { "name" : "004", - "id" : "004", "data" : [ [ "Perl", @@ -77,9 +70,12 @@ "Blog", 10 ] - ] + ], + "id" : "004" }, { + "id" : "005", + "name" : "005", "data" : [ [ "Perl", @@ -93,13 +89,10 @@ "Blog", 12 ] - ], - "id" : "005", - "name" : "005" + ] }, { "id" : "006", - "name" : "006", "data" : [ [ "Perl", @@ -113,9 +106,12 @@ "Blog", 7 ] - ] + ], + "name" : "006" }, { + "id" : "007", + "name" : "007", "data" : [ [ "Perl", @@ -129,12 +125,9 @@ "Blog", 10 ] - ], - "name" : "007", - "id" : "007" + ] }, { - "id" : "008", "name" : "008", "data" : [ [ @@ -149,9 +142,11 @@ "Blog", 12 ] - ] + ], + "id" : "008" }, { + "name" : "009", "data" : [ [ "Perl", @@ -166,8 +161,7 @@ 13 ] ], - "id" : "009", - "name" : "009" + "id" : "009" }, { "data" : [ @@ -184,8 +178,8 @@ 11 ] ], - "id" : "010", - "name" : "010" + "name" : "010", + "id" : "010" }, { "id" : "011", @@ -206,6 +200,7 @@ ] }, { + "name" : "012", "data" : [ [ "Perl", @@ -220,8 +215,7 @@ 11 ] ], - "id" : "012", - "name" : "012" + "id" : "012" }, { "data" : [ @@ -242,6 +236,7 @@ "id" : "013" }, { + "name" : "014", "data" : [ [ "Perl", @@ -256,7 +251,6 @@ 15 ] ], - "name" : "014", "id" : "014" }, { @@ -278,6 +272,7 @@ ] }, { + "id" : "016", "data" : [ [ "Perl", @@ -292,7 +287,6 @@ 12 ] ], - "id" : "016", "name" : "016" }, { @@ -310,11 +304,10 @@ 12 ] ], - "id" : "017", - "name" : "017" + "name" : "017", + "id" : "017" }, { - "name" : "018", "id" : "018", "data" : [ [ @@ -329,9 +322,11 @@ "Blog", 14 ] - ] + ], + "name" : "018" }, { + "name" : "019", "data" : [ [ "Perl", @@ -346,10 +341,10 @@ 13 ] ], - "name" : "019", "id" : "019" }, { + "id" : "020", "data" : [ [ "Perl", @@ -364,10 +359,10 @@ 13 ] ], - "name" : "020", - "id" : "020" + "name" : "020" }, { + "id" : "021", "data" : [ [ "Perl", @@ -382,7 +377,6 @@ 10 ] ], - "id" : "021", "name" : "021" }, { @@ -440,8 +434,6 @@ "id" : "024" }, { - "id" : "025", - "name" : "025", "data" : [ [ "Perl", @@ -455,9 +447,12 @@ "Blog", 12 ] - ] + ], + "name" : "025", + "id" : "025" }, { + "name" : "026", "data" : [ [ "Perl", @@ -472,12 +467,10 @@ 10 ] ], - "name" : "026", "id" : "026" }, { "id" : "027", - "name" : "027", "data" : [ [ "Perl", @@ -491,11 +484,11 @@ "Blog", 9 ] - ] + ], + "name" : "027" }, { "name" : "028", - "id" : "028", "data" : [ [ "Perl", @@ -509,9 +502,12 @@ "Blog", 9 ] - ] + ], + "id" : "028" }, { + "id" : "029", + "name" : "029", "data" : [ [ "Perl", @@ -525,12 +521,9 @@ "Blog", 12 ] - ], - "id" : "029", - "name" : "029" + ] }, { - "name" : "030", "id" : "030", "data" : [ [ @@ -545,9 +538,11 @@ "Blog", 10 ] - ] + ], + "name" : "030" }, { + "id" : "031", "data" : [ [ "Perl", @@ -562,11 +557,9 @@ 9 ] ], - "id" : "031", "name" : "031" }, { - "name" : "032", "id" : "032", "data" : [ [ @@ -581,9 +574,11 @@ "Blog", 10 ] - ] + ], + "name" : "032" }, { + "name" : "033", "data" : [ [ "Perl", @@ -598,12 +593,10 @@ 10 ] ], - "name" : "033", "id" : "033" }, { "name" : "034", - "id" : "034", "data" : [ [ "Perl", @@ -617,10 +610,10 @@ "Blog", 11 ] - ] + ], + "id" : "034" }, { - "id" : "035", "name" : "035", "data" : [ [ @@ -635,10 +628,10 @@ "Blog", 9 ] - ] + ], + "id" : "035" }, { - "id" : "036", "name" : "036", "data" : [ [ @@ -653,9 + |
