diff options
22 files changed, 2097 insertions, 1748 deletions
diff --git a/challenge-169/ulrich-rieke/cpp/ch-1.cpp b/challenge-169/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..2d4d8011f4 --- /dev/null +++ b/challenge-169/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,46 @@ +#include <iostream> +#include <vector> +#include <string> +#include <algorithm> + +std::vector<int> primeDecompose( int n ) { + std::vector<int> primeFactors ; + int current = 2 ; + while ( n != 1 ) { + if ( n % current == 0 ) { + primeFactors.push_back( current ) ; + n /= current ; + } + else { + current++ ; + } + } + return primeFactors ; +} + +bool isBrilliant( int n ) { + std::vector<int> primeFactors( primeDecompose( n ) ) ; + if ( primeFactors.size( ) == 2 ) { + std::vector<std::string> primeNumbers( 2 ) ; + std::transform( primeFactors.begin( ) , primeFactors.end( ) , + primeNumbers.begin( ) , []( int i ){ return std::to_string( i ) ;} ) ; + return primeNumbers.begin()->length( ) == primeNumbers.back().length( ) ; + } + else { + return false ; + } +} + +int main( ) { + std::vector<int> brilliantNumbers ; + int current = 2 ; + while ( brilliantNumbers.size( ) != 20 ) { + if ( isBrilliant( current ) ) + brilliantNumbers.push_back( current ) ; + current++ ; + } + for ( int i : brilliantNumbers ) + std::cout << i << " " ; + std::cout << std::endl ; + return 0 ; +} diff --git a/challenge-169/ulrich-rieke/cpp/ch-2.cpp b/challenge-169/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..ffbcfcdd34 --- /dev/null +++ b/challenge-169/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,66 @@ +#include <iostream> +#include <algorithm> +#include <map> +#include <vector> +#include <numeric> +#include <iterator> + +std::vector<int> primeDecompose( int n ) { + std::vector<int> primeFactors ; + int current = 2 ; + while ( n != 1 ) { + if ( n % current == 0 ) { + primeFactors.push_back( current ) ; + n /= current ; + } + else { + current++ ; + } + } + return primeFactors ; +} + +int my_gcd( int a , int b ) { + std::vector<int> firstFactors( primeDecompose( a ) ) ; + std::vector<int> secondFactors( primeDecompose( b ) ) ; + std::vector<int> common ; + std::set_intersection( firstFactors.begin( ) , firstFactors.end( ) , + secondFactors.begin( ) , secondFactors.end( ) , + std::inserter( common, common.begin( ) )) ; + return std::accumulate( common.begin( ) , common.end( ) , 1 , + std::multiplies( ) ) ; +} + +bool isAchilles( int n ) { + std::vector<int> primeFactors( primeDecompose( n ) ) ; + std::map<int , int> factorCount ; + for ( int i : primeFactors ) { + factorCount[ i ]++ ; + } + std::vector<int> exponents ; + for ( auto it = factorCount.begin( ) ; it != factorCount.end( ) ; ++it ) { + exponents.push_back( it->second ) ; + } + if ( *std::min_element(exponents.begin( ) , exponents.end( ) ) >= 2 ) { + int start = *exponents.begin( ) ; + return (std::accumulate( exponents.begin( ) , exponents.end( ) , start , + []( int a , int b ){ return my_gcd( a , b ) ; } ) == 1 ) ; + } + else + return false ; +} + +int main( ) { + std::vector<int> achillesNumbers ; + int current = 2 ; + while ( achillesNumbers.size( ) != 20 ) { + if ( isAchilles( current ) ) { + achillesNumbers.push_back( current ) ; + } + current++ ; + } + for ( int i : achillesNumbers ) + std::cout << i << " " ; + std::cout << std::endl ; + return 0 ; +} diff --git a/challenge-169/ulrich-rieke/haskell/ch-1.hs b/challenge-169/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..704ef0c9b1 --- /dev/null +++ b/challenge-169/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,26 @@ +module Challenge169 + where + +divisors :: Int -> [Int] +divisors n = [d | d <- [2 .. n] , mod n d == 0 ] + +primeDecompose :: Int -> [Int] +primeDecompose n = snd $ until ( (== 1) . fst ) step (n , [] ) +where + step :: ( Int , [Int] ) -> ( Int , [Int] ) + step ( d , list ) = ( div d h , list ++ [h] ) + where + h = head $ divisors d + +isBrilliant :: Int -> Bool +isBrilliant n = (( length primeFactors ) == 2) && (l1 == l2 ) +where + primeFactors :: [Int] + primeFactors = primeDecompose n + l1 :: Int + l1 = length $ show $ head primeFactors + l2 :: Int + l2 = length $ show $ last primeFactors + +solution :: [Int] +solution = take 20 $ filter isBrilliant [2 , 3 ..] diff --git a/challenge-169/ulrich-rieke/haskell/ch-2.hs b/challenge-169/ulrich-rieke/haskell/ch-2.hs new file mode 100644 index 0000000000..f3d2184277 --- /dev/null +++ b/challenge-169/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,25 @@ +module Challenge169_2 + where +import Data.List ( group ) + +divisors :: Int -> [Int] +divisors n = [d | d <- [2 .. n] , mod n d == 0 ] + +primeDecompose :: Int -> [Int] +primeDecompose n = snd $ until ( (== 1) . fst ) step (n , [] ) +where + step :: ( Int , [Int] ) -> ( Int , [Int] ) + step ( d , list ) = ( div d h , list ++ [h] ) + where + h = head $ divisors d + +isAchilles :: Int -> Bool +isAchilles n = myCondition && ( (foldl1 gcd theLengths ) == 1 ) +where + theLengths :: [Int] + theLengths = map length $ group $ primeDecompose n + myCondition :: Bool + myCondition = if null theLengths then False else (minimum theLengths) >= 2 + +solution :: [Int] +solution = take 20 $ filter isAchilles [2 , 3 ..] diff --git a/challenge-169/ulrich-rieke/perl/ch-1.pl b/challenge-169/ulrich-rieke/perl/ch-1.pl new file mode 100644 index 0000000000..59be1f066b --- /dev/null +++ b/challenge-169/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +sub primeDecompose { + my $number = shift ; + my $current = 2 ; + my @primeFactors ; + while ( $number != 1 ) { + if ( $number % $current == 0 ) { + push @primeFactors, $current ; + $number /= $current ; + } + else { + $current++ ; + } + } + return @primeFactors ; +} + +sub isBrilliant { + my $number = shift ; + my @primeFactors = primeDecompose( $number ) ; + return ( (scalar( @primeFactors ) == 2 ) && ( length( $primeFactors[0] ) + == length( $primeFactors[1] ))) ; +} + +my @brilliantNumbers ; +my $current = 1 ; +while ( scalar( @brilliantNumbers ) != 20 ) { + if ( isBrilliant( $current ) ) { + push @brilliantNumbers , $current ; + } + $current++ ; +} +say join( ',' , @brilliantNumbers ) ; diff --git a/challenge-169/ulrich-rieke/perl/ch-2.pl b/challenge-169/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..d2f5c0af99 --- /dev/null +++ b/challenge-169/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; +use List::Util qw ( min max reduce ) ; + +sub primeDecompose { + my $number = shift ; + my $current = 2 ; + my @primeFactors ; + while ( $number != 1 ) { + if ( $number % $current == 0 ) { + push @primeFactors, $current ; + $number /= $current ; + } + else { + $current++ ; + } + } + return @primeFactors ; +} + +sub gcd { + my $first = shift ; + my $second = shift ; + my %firstDivisors ; + my %secondDivisors ; + for my $n ( 1 .. $first ) { + if ( $first % $n == 0 ) { + $firstDivisors{ $n }++ ; + } + } + for my $n ( 1 .. $second ) { + if ( $second % $n == 0 ) { + $secondDivisors{ $n }++ ; + } + } + my @common = grep { exists ($secondDivisors{$_}) } keys %firstDivisors ; + return max( @common ) ; +} + +sub isAchilles { + my $number = shift ; + my @primeFactors = primeDecompose( $number ) ; + my %achilles ; + for my $n ( @primeFactors ) { + $achilles{$n}++ ; + } + my @frequencies = values( %achilles ) ; + my $minFactor = min( @frequencies ) ; + if ( $minFactor < 2 ) { + return 0 ; + } + else { + return ( (reduce { gcd( $a , $b ) } @frequencies) == 1 ) ; + } +} + +my @achillesNumbers ; +my $current = 2 ; +while ( scalar( @achillesNumbers ) != 20 ) { + if ( isAchilles( $current ) ) { + push @achillesNumbers , $current ; + } + $current++ ; +} +say join( ',' , @achillesNumbers ) ; diff --git a/challenge-169/ulrich-rieke/raku/ch-1.raku b/challenge-169/ulrich-rieke/raku/ch-1.raku new file mode 100644 index 0000000000..ce2705bccc --- /dev/null +++ b/challenge-169/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,30 @@ +use v6 ; + +sub primeDecompose( Int $n is copy ) { + my @primeFactors ; + my $current = 2 ; + while ( $n != 1 ) { + while ( not ( $n %% $current ) ) { + $current++ ; + } + @primeFactors.push( $current ) ; + $n div= $current ; + } + return @primeFactors ; +} + +sub isBrilliant( Int $n is copy --> Bool ) { + my @primeFactors = primeDecompose( $n ) ; + return ( @primeFactors.elems == 2 ) && ( ~(@primeFactors[0]).chars == + ~(@primeFactors[1].chars )) ; +} + +my @brilliantNumbers ; +my $current = 2 ; +while ( @brilliantNumbers.elems != 20 ) { + if ( isBrilliant( $current ) ) { + @brilliantNumbers.push( $current ) ; + } + $current++ ; +} +say @brilliantNumbers.join( ',') ; diff --git a/challenge-169/ulrich-rieke/raku/ch-2.raku b/challenge-169/ulrich-rieke/raku/ch-2.raku new file mode 100644 index 0000000000..f04f39e218 --- /dev/null +++ b/challenge-169/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,33 @@ +use v6 ; + +sub primeDecompose( Int $n is copy ) { + my @primeFactors ; + my $current = 2 ; + while ( $n != 1 ) { + while ( not ( $n %% $current ) ) { + $current++ ; + } + @primeFactors.push( $current ) ; + $n div= $current ; + } + return @primeFactors ; +} + +sub isAchillesNumber( Int $n is copy --> Bool ) { + my @primeFactors = primeDecompose( $n ) ; + my %achilles ; + for @primeFactors -> $i { + %achilles{~$i}++ ; + } + return (%achilles.values.min >= 2) && (([gcd] %achilles.values) == 1 ) ; +} + +my @achillesNumbers ; +my $current = 2 ; +while (@achillesNumbers.elems != 20 ) { + if ( isAchillesNumber( $current ) ) { + @achillesNumbers.push( $current ) ; + } + $current++ ; +} +say @achillesNumbers.join( ', ' ) ; diff --git a/stats/pwc-current.json b/stats/pwc-current.json index f59115fdb5..91e1c796f5 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,28 +1,7 @@ { - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "xAxis" : { - "type" : "category" - }, - "subtitle" : { - "text" : "[Champions: 9] Last updated at 2022-06-14 20:05:56 GMT" - }, - "title" : { - "text" : "The Weekly Challenge - 169" - }, - "legend" : { - "enabled" : 0 - }, - "chart" : { - "type" : "column" - }, "drilldown" : { "series" : [ { - "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -33,6 +12,7 @@ 6 ] ], + "id" : "Luca Ferrari", "name" : "Luca Ferrari" }, { @@ -46,7 +26,6 @@ "id" : "Mark Anderson" }, { - "id" : "Peter Campbell Smith", "name" : "Peter Campbell Smith", "data" : [ [ @@ -57,29 +36,32 @@ "Blog", 1 ] - ] + ], + "id" : "Peter Campbell Smith" }, { + "name" : "PokGoPun", + "id" : "PokGoPun", "data" : [ [ "Perl", 2 ] - ], - "name" : "PokGoPun", - "id" : "PokGoPun" + ] }, { - "id" : "Robert DiCicco", "data" : [ [ "Raku", 1 ] ], + "id" : "Robert DiCicco", "name" : "Robert DiCicco" }, { + "name" : "Roger Bell_West", + "id" : "Roger Bell_West", "data" : [ [ "Perl", @@ -89,12 +71,11 @@ "Raku", 2 ] - ], - "name" : "Roger Bell_West", - "id" : "Roger Bell_West" + ] }, { "name" : "Simon Green", + "id" : "Simon Green", "data" : [ [ "Perl", @@ -104,11 +85,24 @@ "Blog", 1 ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] ], - "id" : "Simon Green" + "id" : "Stephen G Lynn", + "name" : "Stephen G Lynn" }, { - "name" : "Stephen G Lynn", + "name" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -119,7 +113,7 @@ 2 ] ], - "id" : "Stephen G Lynn" + "id" : "Ulrich Rieke" }, { "data" : [ @@ -132,76 +126,101 @@ 1 ] ], - "name" : "W. Luis Mochan", - "id" : "W. Luis Mochan" + "id" : "W. Luis Mochan", + "name" : "W. Luis Mochan" } ] }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } - } - }, - "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/>" + "xAxis" : { + "type" : "category" }, "series" : [ { - "colorByPoint" : 1, "data" : [ { + "drilldown" : "Luca Ferrari", "y" : 8, - "name" : "Luca Ferrari", - "drilldown" : "Luca Ferrari" + "name" : "Luca Ferrari" }, { + "name" : "Mark Anderson", "y" : 2, - "drilldown" : "Mark Anderson", - "name" : "Mark Anderson" + "drilldown" : "Mark Anderson" }, { + "name" : "Peter Campbell Smith", "y" : 3, - "drilldown" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + "drilldown" : "Peter Campbell Smith" }, { - "y" : 2, "name" : "PokGoPun", + "y" : 2, "drilldown" : "PokGoPun" }, { - "drilldown" : "Robert DiCicco", + "y" : 1, "name" : "Robert DiCicco", - "y" : 1 + "drilldown" : "Robert DiCicco" }, { - "name" : "Roger Bell_West", "drilldown" : "Roger Bell_West", - "y" : 4 + "y" : 4, + "name" : "Roger Bell_West" }, { - "name" : "Simon Green", "drilldown" : "Simon Green", - "y" : 3 + "y" : 3, + "name" : "Simon Green" }, { + "name" : "Stephen G Lynn", "y" : 4, - "drilldown" : "Stephen G Lynn", - "name" : "Stephen G Lynn" + "drilldown" : "Stephen G Lynn" + }, + { + "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke", + "y" : 4 }, { "y" : 3, - "drilldown" : "W. Luis Mochan", - "name" : "W. Luis Mochan" + "name" : "W. Luis Mochan", + "drilldown" : "W. Luis Mochan" } ], - "name" : "The Weekly Challenge - 169" + "name" : "The Weekly Challenge - 169", + "colorByPoint" : 1 + } + ], + "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/>" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" } - ] + }, + "chart" : { + "type" : "column" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "subtitle" : { + "text" : "[Champions: 10] Last updated at 2022-06-14 20:41:46 GMT" + }, + "title" : { + "text" : "The Weekly Challenge - 169" + } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index c59e609bf2..e58bf2ba1a 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -2,8 +2,11 @@ "chart" : { "type" : "column" }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2022]" + }, + "subtitle" : { + "text" : "Last updated at 2022-06-14 20:41:46 GMT" }, "series" : [ { @@ -14,36 +17,36 @@ ], [ "Perl", - 8208 + 8210 ], [ "Raku", - 4872 + 4874 ] ], "name" : "Contributions", "dataLabels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - }, + "format" : "{point.y:.0f}", "color" : "#FFFFFF", "y" : 10, "rotation" : -90, + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + }, "align" : "right", - "enabled" : "true", - "format" : "{point.y:.0f}" + "enabled" : "true" } } ], "xAxis" : { - "type" : "category", "labels" : { "style" : { "fontFamily" : "Verdana, sans-serif", "fontSize" : "13px" } - } + }, + "type" : "category" }, "yAxis" : { "min" : 0, @@ -51,11 +54,8 @@ "text" : null } }, - "subtitle" : { - "text" : "Last updated at 2022-06-14 20:05:56 GMT" - }, - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2022]" + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" }, "legend" : { "enabled" : "false" diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 1d897066af..26a0f7088a 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,8 +1,879 @@ { + "chart" : { + "type" : "column" + }, + "title" : { + "text" : "The Weekly Challenge Language" + }, + "subtitle" : { + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2022-06-14 20:41:46 GMT" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } + } + }, + "series" : [ + { + "data" : [ + { + "name" : "#001", + "y" : 161, + "drilldown" : "001" + }, + { + "y" : 125, + "name" : "#002", + "drilldown" : "002" + }, + { + "name" : "#003", + "y" : 83, + "drilldown" : "003" + }, + { + "drilldown" : "004", + "name" : "#004", + "y" : 99 + }, + { + "name" : "#005", + "y" : 78, + "drilldown" : "005" + }, + { + "drilldown" : "006", + "y" : 58, + "name" : "#006" + }, + { + "drilldown" : "007", + "y" : 64, + "name" : "#007" + }, + { + "name" : "#008", + "y" : 78, + "drilldown" : "008" + }, + { + "drilldown" : "009", + "name" : "#009", + "y" : 76 + }, + { + "drilldown" : "010", + "name" : "#010", + "y" : 65 + }, + { + "y" : 85, + "name" : "#011", + "drilldown" : "011" + }, + { + "drilldown" : "012", + "y" : 89, + "name" : "#012" + }, + { + "drilldown" : "013", + "name" : "#013", + "y" : 85 + }, + { + "drilldown" : "014", + "y" : 101, + "name" : "#014" + }, + { + "name" : "#015", + "y" : 99, + "drilldown" : "015" + }, + { + "y" : 71, + "name" : "#016", + "drilldown" : "016" + }, + { + "drilldown" : "017", + "name" : "#017", + "y" : 84 + }, + { + "name" : "#018", + "y" : 81, + "drilldown" : "018" + }, + { + "drilldown" : "019", + "y" : 103, + "name" : "#019" + }, + { + "drilldown" : "020", + "name" : "#020", + "y" : 101 + }, + { + "name" : "#021", + "y" : 72, + "drilldown" : "021" + }, + { + "drilldown" : "022", + "y" : 68, + "name" : "#022" + }, + { + "drilldown" : "023", + "name" : "#023", + "y" : 97 + }, + { + "name" : "#024", + "y" : 75, + "drilldown" : "024" + }, + { + "drilldown" : "025", + "name" : "#025", + "y" : 59 + }, + { + "y" : 74, + "name" : "#026", + "drilldown" : "026" + }, + { + "name" : "#027", + "y" : 62, + "drilldown" : "027" + }, + { + "y" : 82, + "name" : "#028", + "drilldown" : "028" + }, + { + "drilldown" : "029", + "y" : 81, + "name" : "#029" + }, + { + "drilldown" : "030", + "y" : 119, + "name" : "#030" + }, + { + "y" : 91, + "name" : "#031", + "drilldown" : "031" + }, + { + "y" : 96, + "name" : "#032", + "drilldown" : "032" + }, + { + "drilldown" : "033", + "y" : 112, + "name" : "#033" + }, + { + "name" : "#034", + "y" : 66, + "drilldown" : "034" + }, + { + "drilldown" : "035", + "name" : "#035", + "y" : 66 + }, + { + "y" : 70, + "name" : "#036", + "drilldown" : "036" + }, + { + "drilldown" : "037", + "y" : 69, + "name" : "#037" + }, + { + "drilldown" : "038", + "name" : "#038", + "y" : 70 + }, + { + "drilldown" : "039", + "y" : 64, + "name" : "#039" + }, + { + "name" : "#040", + "y" : 75, + "drilldown" : "040" + }, + { + "name" : "#041", + "y" : 78, + "drilldown" : "041" + }, + { + "name" : "#042", + "y" : 94, + "drilldown" : "042" + }, + { + "y" : 70, + "name" : "#043", + "drilldown" : "043" + }, + { + "y" : 87, + "name" : "#044", + "drilldown" : "044" + }, + { + "name" : "#045", + "y" : 98, + "drilldown" : "045" + }, + { + "drilldown" : "046", + "y" : 89, + "name" : "#046" + }, + { + "drilldown" : "047", + "name" : "#047", + "y" : 86 + }, + { + "drilldown" : "048", + "y" : 110, + "name" : "#048" + }, + { + "drilldown" : "049", + "y" : 91, + "name" : "#049" + }, + { + "name" : "#050", + "y" : 100, + "drilldown" : "050" + }, + { + "drilldown" : "051", + "y" : 91, + "name" : "#051" + }, + { + "y" : 93, + "name" : "#052", + "drilldown" : "052" + }, + { + "drilldown" : "053", + "name" : "#053", + "y" : 103 + }, + { + "drilldown" : "054", + "name" : "#054", + "y" : 105 + }, + { + "name" : "#055", + "y" : 90, + "drilldown" : "055" + }, |
