diff options
22 files changed, 1497 insertions, 1293 deletions
diff --git a/challenge-153/ulrich-rieke/cpp/ch-1.cpp b/challenge-153/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..990ee9c29a --- /dev/null +++ b/challenge-153/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,28 @@ +#include <iostream> + +int factorial( int num ) { + if ( num == 0 ) { + return 1 ; + } + else { + int fac = 1 ; + for ( int i = 1 ; i < num + 1 ; i++ ) + fac *= i ; + return fac ; + } +} + +int leftFactorial( int n ) { + int sum = 0 ; + for ( int i = 0 ; i < n + 1 ; i++ ) + sum += factorial( i ) ; + return sum ; +} + +int main( ) { + for ( int i = 0 ; i < 10 ; i++ ) { + std::cout << leftFactorial( i ) << " " ; + } + std::cout << std::endl ; + return 0 ; +} diff --git a/challenge-153/ulrich-rieke/cpp/ch-2.cpp b/challenge-153/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..51fd65fda0 --- /dev/null +++ b/challenge-153/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,34 @@ +#include <iostream> +#include <cstdlib> +#include <vector> +#include <algorithm> +#include <numeric> + +int factorial( int num ) { + if ( num == 0 ) { + return 1 ; + } + else { + int fac = 1 ; + for ( int i = 1 ; i < num + 1 ; i++ ) + fac *= i ; + return fac ; + } +} + +int main( int argc, char* argv[] ) { + int n = std::atoi( argv[1] ) ; + int c = n ; //we are "destroying" n in the next lines + std::vector<int> digits ; + while ( n != 0 ) { + digits.push_back( n % 10 ) ; + n /= 10 ; + } + std::transform( digits.begin( ) , digits.end( ) , digits.begin( ) , + factorial ) ; + if ( std::accumulate( digits.begin( ) , digits.end( ) , 0 ) == c ) + std::cout << 1 << std::endl ; + else + std::cout << 0 << std::endl ; + return 0 ; +} diff --git a/challenge-153/ulrich-rieke/haskell/ch-1.hs b/challenge-153/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..4a5d062286 --- /dev/null +++ b/challenge-153/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,13 @@ +module Challenge153 + where + +factorial :: Int -> Int +factorial n + |n == 0 = 1 + |n > 0 = product [1 .. n] + +leftFactorial :: Int -> Int +leftFactorial n = sum $ map factorial [0 .. n - 1] + +solution :: [Int] +solution = map leftFactorial [1 .. 10] diff --git a/challenge-153/ulrich-rieke/haskell/ch-2.hs b/challenge-153/ulrich-rieke/haskell/ch-2.hs new file mode 100644 index 0000000000..efcf8ac98e --- /dev/null +++ b/challenge-153/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,14 @@ +module Challenge153_2 + where +import Data.Char ( digitToInt ) + +factorial :: Int -> Int +factorial n + |n == 0 = 1 + |n > 0 = product [1 .. n] + +solution :: Int -> Int +solution n = if myCondition n then 1 else 0 +where + myCondition :: Int -> Bool + myCondition num = sum ( map ( factorial . digitToInt ) $ show num ) == num diff --git a/challenge-153/ulrich-rieke/perl/ch-1.pl b/challenge-153/ulrich-rieke/perl/ch-1.pl new file mode 100644 index 0000000000..b49151a4da --- /dev/null +++ b/challenge-153/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use List::Util qw (product ) ; +use feature 'say' ; + +sub factorial { + my $number = shift ; + if ( $number == 0 ) { + return 1 ; + } + else { + return product( 1 .. $number ) ; + } +} + +sub leftFactorial { + my $number = shift ; + my $sum = 0 ; + map { $sum += factorial( $_ ) } (0 .. $number - 1 ) ; + return $sum ; +} + +my @leftFactorials ; +for my $i (1 .. 10) { + push @leftFactorials , leftFactorial( $i ) ; +} +say join( ',' , @leftFactorials) ; diff --git a/challenge-153/ulrich-rieke/perl/ch-2.pl b/challenge-153/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..3fabec7f5b --- /dev/null +++ b/challenge-153/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; +use List::Util qw ( sum product ) ; + +sub factorial { + my $number = shift ; + if ( $number == 0 ) { + return 1 ; + } + else { + return product( 1 .. $number ) ; + } +} + +my $n = $ARGV[ 0 ] ; +my @digits = split( // , $n ) ; +if ( sum( map { factorial( $_ ) } @digits ) == $n ) { + say 1 ; +} +else { + say 0 ; +} diff --git a/challenge-153/ulrich-rieke/raku/ch-1.raku b/challenge-153/ulrich-rieke/raku/ch-1.raku new file mode 100644 index 0000000000..9aa8ecce79 --- /dev/null +++ b/challenge-153/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,22 @@ +use v6 ; + +sub factorial( Int $n is copy ) { + if ( $n == 0 ) { + return 1 ; + } + else { + return [*](1 .. $n) ; + } +} + +sub leftFactorial( Int $n --> Int ) { + my $sum = 0 ; + (0 .. $n - 1 ).map( { $sum += factorial( $_ ) } ) ; + return $sum ; +} + +my @leftFactorials ; +for (1 .. 10 ) -> $i { + @leftFactorials.push( leftFactorial( $i ) ) ; +} +say @leftFactorials ; diff --git a/challenge-153/ulrich-rieke/raku/ch-2.raku b/challenge-153/ulrich-rieke/raku/ch-2.raku new file mode 100644 index 0000000000..a0730b87aa --- /dev/null +++ b/challenge-153/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,22 @@ +use v6 ; + +sub factorial( Int $n is copy ) { + if ( $n == 0 ) { + return 1 ; + } + else { + return [*](1 .. $n) ; + } +} + +sub MAIN( Int $n is copy ) { + my @digits = (~$n).comb.map( {.Int} ) ; + my $sum = 0 ; + @digits.map( { $sum += factorial( $_ ) } ) ; + if ( $sum == $n ) { + say 1 ; + } + else { + say 0 ; + } +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 04b6d7c879..765e6053bc 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,27 +1,4 @@ { - "xAxis" : { - "type" : "category" - }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - } - } - }, - "legend" : { - "enabled" : 0 - }, - "chart" : { - "type" : "column" - }, - "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 - }, "drilldown" : { "series" : [ { @@ -35,16 +12,18 @@ "id" : "Abigail" }, { - "name" : "E. Choroba", - "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "E. Choroba", + "name" : "E. Choroba" }, { + "name" : "Luca Ferrari", + "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -54,28 +33,26 @@ "Blog", 2 ] - ], - "id" : "Luca Ferrari", - "name" : "Luca Ferrari" + ] }, { - "name" : "Mark Anderson", - "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Mark Anderson", + "name" : "Mark Anderson" }, { - "id" : "Marton Polgar", "data" : [ [ "Raku", 2 ] ], + "id" : "Marton Polgar", "name" : "Marton Polgar" }, { @@ -93,16 +70,17 @@ "name" : "Peter Campbell Smith" }, { - "id" : "PokGoPun", "data" : [ [ "Perl", 2 ] ], + "id" : "PokGoPun", "name" : "PokGoPun" }, { + "name" : "Robert DiCicco", "data" : [ [ "Perl", @@ -113,8 +91,7 @@ 2 ] ], - "id" : "Robert DiCicco", - "name" : "Robert DiCicco" + "id" : "Robert DiCicco" }, { "id" : "Roger Bell_West", @@ -137,6 +114,20 @@ 2 ], [ + "Raku", + 2 + ] + ], + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ "Blog", 1 ] @@ -149,48 +140,76 @@ "title" : { "text" : "The Weekly Challenge - 153" }, + "tooltip" : { + "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/>", + "followPointer" : 1 + }, + "chart" : { + "type" : "column" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } + } + }, + "xAxis" : { + "type" : "category" + }, + "subtitle" : { + "text" : "[Champions: 11] Last updated at 2022-02-21 20:23:13 GMT" + }, "yAxis" : { "title" : { "text" : "Total Solutions" } }, + "legend" : { + "enabled" : 0 + }, "series" : [ { + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 153", "data" : [ { - "name" : "Abigail", + "y" : 2, "drilldown" : "Abigail", - "y" : 2 + "name" : "Abigail" }, { "name" : "E. Choroba", - "y" : 2, - "drilldown" : "E. Choroba" + "drilldown" : "E. Choroba", + "y" : 2 }, { - "name" : "Luca Ferrari", + "y" : 4, "drilldown" : "Luca Ferrari", - "y" : 4 + "name" : "Luca Ferrari" }, { - "name" : "Mark Anderson", "drilldown" : "Mark Anderson", + "name" : "Mark Anderson", "y" : 2 }, { + "y" : 2, "name" : "Marton Polgar", - "drilldown" : "Marton Polgar", - "y" : 2 + "drilldown" : "Marton Polgar" }, { - "y" : 3, "drilldown" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "y" : 3 }, { + "name" : "PokGoPun", "drilldown" : "PokGoPun", - "y" : 2, - "name" : "PokGoPun" + "y" : 2 }, { "y" : 4, @@ -199,20 +218,20 @@ }, { "name" : "Roger Bell_West", - "y" : 4, - "drilldown" : "Roger Bell_West" + "drilldown" : "Roger Bell_West", + "y" : 4 + }, + { + "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke", + "y" : 4 }, { + "y" : 3, "name" : "W. Luis Mochan", - "drilldown" : "W. Luis Mochan", - "y" : 3 + "drilldown" : "W. Luis Mochan" } - ], - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 153" + ] } - ], - "subtitle" : { - "text" : "[Champions: 10] Last updated at 2022-02-21 20:09:15 GMT" - } + ] } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index f0c6a3b5c9..f239cce585 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,27 +1,25 @@ { - "xAxis" : { - "type" : "category", - "labels" : { - "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" - } + "yAxis" : { + "min" : 0, + "title" : { + "text" : null } }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, - "subtitle" : { - "text" : "Last updated at 2022-02-21 20:09:15 GMT" - }, - "chart" : { - "type" : "column" - }, - "legend" : { - "enabled" : "false" - }, "series" : [ { + "name" : "Contributions", + "dataLabels" : { + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + }, + "color" : "#FFFFFF", + "y" : 10, + "align" : "right", + "enabled" : "true", + "rotation" : -90, + "format" : "{point.y:.0f}" + }, "data" : [ [ "Blog", @@ -29,33 +27,35 @@ ], [ "Perl", - 7340 + 7342 ], [ "Raku", - 4411 + 4413 ] - ], - "dataLabels" : { - "color" : "#FFFFFF", - "y" : 10, - "align" : "right", - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - }, - "format" : "{point.y:.0f}", - "enabled" : "true", - "rotation" : -90 - }, - "name" : "Contributions" + ] } ], - "yAxis" : { - "title" : { - "text" : null - }, - "min" : 0 + "legend" : { + "enabled" : "false" + }, + "subtitle" : { + "text" : "Last updated at 2022-02-21 20:23:13 GMT" + }, + "xAxis" : { + "type" : "category", + "labels" : { + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + } + } + }, + "chart" : { + "type" : "column" + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2022]" diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 7186ee5c0b..41cca9dcdb 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,7 +1,28 @@ { + "chart" : { + "type" : "column" + }, + "plotOptions" : { + "series" : { + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + }, + "borderWidth" : 0 + } + }, + "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/>" + }, + "title" : { + "text" : "The Weekly Challenge Language" + }, "drilldown" : { "series" : [ { + "id" : "001", "data" : [ [ "Perl", @@ -16,11 +37,9 @@ 11 ] ], - "id" : "001", "name" : "001" }, { - "id" : "002", "data" : [ [ "Perl", @@ -35,10 +54,10 @@ 10 ] ], + "id" : "002", "name" : "002" }, { - "id" : "003", "data" : [ [ "Perl", @@ -53,9 +72,11 @@ 9 ] ], + "id" : "003", "name" : "003" }, { + "name" : "004", "data" : [ [ "Perl", @@ -70,11 +91,11 @@ 10 ] ], - "id" : "004", - "name" : "004" + "id" : "004" }, { "name" : "005", + "id" : "005", "data" : [ [ "Perl", @@ -88,10 +109,10 @@ "Blog", 12 ] - ], - "id" : "005" + ] }, { + "name" : "006", "data" : [ [ "Perl", @@ -106,8 +127,7 @@ 7 ] ], - "id" : "006", - "name" : "006" + "id" : "006" }, { "id" : "007", @@ -147,7 +167,6 @@ }, { "name" : "009", - "id" : "009", "data" : [ [ "Perl", @@ -161,7 +180,8 @@ "Blog", 13 ] - ] + ], + "id" : "009" }, { "name" : "010", @@ -219,6 +239,7 @@ }, { "name" : "013", + "id" : "013", "data" : [ [ "Perl", @@ -232,10 +253,11 @@ "Blog", 13 ] - ], - "id" : "013" + ] }, { + "name" : "014", + "id" : "014", "data" : [ [ "Perl", @@ -249,11 +271,10 @@ "Blog", 15 ] - ], - "id" : "014", - "name" : "014" + ] }, { + "name" : "015", "data" : [ [ "Perl", @@ -268,11 +289,9 @@ 15 ] ], - "id" : "015", - "name" : "015" + "id" : "015" }, { - "name" : "016", "data" : [ [ "Perl", @@ -287,10 +306,11 @@ 12 ] ], - "id" : "016" + "id" : "016", + "name" : "016" }, { - "name" : "017", + "id" : "017", "data" : [ [ "Perl", @@ -305,10 +325,9 @@ 12 ] ], - "id" : "017" + "name" : "017" }, { - "name" : "018", "data" : [ [ "Perl", @@ -323,7 +342,8 @@ 14 ] ], - "id" : "018" + "id" : "018", + "name" : "018" }, { "name" : "019", @@ -362,7 +382,6 @@ "name" : "020" }, { - "id" : "021", "data" : [ [ "Perl", @@ -377,6 +396,7 @@ 10 ] ], + "id" : "021", "name" : "021" }, { @@ -398,6 +418,7 @@ "name" : "022" }, { + "id" : "023", "data" : [ [ "Perl", @@ -412,7 +433,6 @@ 12 ] ], - "id" : "023", "name" : "023" }, { @@ -434,7 +454,7 @@ "id" : "024" }, { - "name" : "025", + "id" : "025", "data" : [ [ "Perl", @@ -449,10 +469,9 @@ 12 ] ], - "id" : "025" + "name" : "025" }, { - "name" : "026", "id" : "026", "data" : [ [ @@ -467,11 +486,10 @@ "Blog", 10 ] - ] + ], + "name" : "026" }, { - "name" : "027", - "id" : "027", "data" : [ [ "Perl", @@ -485,9 +503,13 @@ "Blog", 9 ] - ] + ], + "id" : "027", + "name" : "027" }, { + "name" : "028", + "id" : "028", "data" : [ [ "Perl", @@ -501,11 +523,10 @@ "Blog", 9 ] - ], - "id" : "028", - "name" : "028" + ] }, { + "name" : "029", "id" : "029", "data" : [ [ @@ -520,12 +541,10 @@ "Blog", 12 ] - ], - "name" : "029" + ] }, { "name" : "030", - "id" : "030", "data" : [ [ "Perl", @@ -539,10 +558,10 @@ "Blog", 10 ] - ] + ], + "id" : "030" }, { - "name" : "031", "data" : [ [ "Perl", @@ -557,10 +576,11 @@ 9 ] ], - "id" : "031" + "id" : "031", + "name" : "031" }, { - "id" : "032", + "name" : "032", "data" : [ [ "Perl", @@ -575,9 +595,10 @@ 10 ] ], - "name" : "032" + "id" : "032" }, { + "id" : "033", "data" : [ [ "Perl", @@ -592,11 +613,9 @@ 10 ] ], - "id" : "033", "name" : "033" }, { - "name" : "034", "id" : "034", "data" : [ [ @@ -611,9 +630,11 @@ "Blog", 11 ] - ] + ], + "name" : "034" }, { + "id" : "035", "data" : [ [ "Perl", @@ -628,11 +649,9 @@ 9 ] ], - "id" : "035", "name" : "035" }, { - "name" : "036", "data" : [ [ "Perl", @@ -647,9 +666,11 @@ 11 ] ], - "id" : "036" + "id" : "036", + "name" : "036" }, { + "id" : "037", "data" : [ [ "Perl", @@ -664,10 +685,11 @@ 9 ] ], - "id" : "037", "name" : "037" }, { + "name" : "038", + "id" : "038", "data" : [ [ "Perl", @@ -681,9 +703,7 @@ "Blog", 12 ] - ], - "id" : "038", - "name" : "038" + ] }, { "id" : "039", @@ -705,7 +725,6 @@ }, { "name" : "040", - "id" : "040", "data" : [ [ "Perl", @@ -719,9 +738,11 @@ "Blog", 10 ] - ] + ], + "id" : "040" }, { + "id" : "041", "data" : [ [ "Perl", @@ -736,10 +757,10 @@ 9 ] ], - "id" : "041", "name" : "041" }, { + "name" : "042", "id" : "042", "data" : [ [ @@ -754,8 +775,7 @@ "Blog", 11 ] - ], - "name" : "042" + ] }, { "name" : "043", @@ -776,6 +796,7 @@ ] }, { + "id" : "044", "data" : [ [ "Perl", @@ -790,11 +811,10 @@ 11 ] ], - "id" : "044", "name" : "044" }, { - "id" : "045", + "name" : "045", "data" : [ [ "Perl", @@ -809,10 +829,9 @@ 11 ] ], - "name" : "045" + "id" : "045" }, { - "name" : "046", |
