diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-10-05 18:56:30 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-10-05 18:56:30 +0100 |
| commit | efd1f80fd2548d7dc6569e0a15bef1484526e8db (patch) | |
| tree | ff308af89fcb11c97ba0bce5a85fe66a1ddc3a8a | |
| parent | 19db2a7cdb383a38a5d1f7500d35353e027f3858 (diff) | |
| download | perlweeklychallenge-club-efd1f80fd2548d7dc6569e0a15bef1484526e8db.tar.gz perlweeklychallenge-club-efd1f80fd2548d7dc6569e0a15bef1484526e8db.tar.bz2 perlweeklychallenge-club-efd1f80fd2548d7dc6569e0a15bef1484526e8db.zip | |
- Added solutions by Ulrich Rieke.
| -rw-r--r-- | challenge-133/ulrich-rieke/cpp/ch-1.cpp | 13 | ||||
| -rw-r--r-- | challenge-133/ulrich-rieke/cpp/ch-2.cpp | 71 | ||||
| -rw-r--r-- | challenge-133/ulrich-rieke/haskell/ch-1.hs | 9 | ||||
| -rw-r--r-- | challenge-133/ulrich-rieke/perl/ch-1.pl | 21 | ||||
| -rw-r--r-- | challenge-133/ulrich-rieke/perl/ch-2.pl | 97 | ||||
| -rw-r--r-- | challenge-133/ulrich-rieke/raku/ch-1.raku | 9 | ||||
| -rw-r--r-- | challenge-133/ulrich-rieke/raku/ch-2.raku | 53 | ||||
| -rw-r--r-- | stats/pwc-current.json | 139 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 56 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 882 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 358 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 42 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 102 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 28 | ||||
| -rw-r--r-- | stats/pwc-summary-211-240.json | 104 | ||||
| -rw-r--r-- | stats/pwc-summary-241-270.json | 48 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 98 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 104 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 118 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 524 |
21 files changed, 1607 insertions, 1315 deletions
diff --git a/challenge-133/ulrich-rieke/cpp/ch-1.cpp b/challenge-133/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..5251662f01 --- /dev/null +++ b/challenge-133/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,13 @@ +#include <iostream> +#include <cstdlib> + +int main( int argc, char * argv[] ) { + int n = std::atoi( argv[ 1 ] ) ; + int current = 0 ; + while ( current * current < n ) + current++ ; + if ( current * current == n ) + std::cout << current << std::endl ; + else + std::cout << --current << std::endl ; +} diff --git a/challenge-133/ulrich-rieke/cpp/ch-2.cpp b/challenge-133/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..2512ef8ee2 --- /dev/null +++ b/challenge-133/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,71 @@ +#include <iostream> +#include <vector> +#include <cmath> +#include <map> +#include <iterator> +#include <algorithm> + +bool isPrime( int n ) { + const int stop = std::sqrt( static_cast<double>( n ) ) ; + for ( int i = 2 ; i <= stop ; i++ ) { + if ( n % i == 0 ) + return false ; + } + return true ; +} + +bool isComposite( int n ) { + return ( ( ! isPrime( n ) ) && ( n != 1 ) ) ; +} + +int findDigitSum( int n ) { + int digitsum = 0 ; + while ( n != 0 ) { + digitsum += ( n % 10 ) ; + n /= 10 ; + } + return digitsum ; +} + +std::vector<int> primeFactorize( int n ) { + std::vector<int> primeFactors ; + int current = 2 ; + while ( n != 1 ) { + if ( n % current == 0 ) { + n /= current ; + primeFactors.push_back( current ) ; + } + else { + do { + current++ ; + } while ( ! isPrime( current ) ) ; + } + } + return primeFactors ; +} + +bool isSmithNumber( int n ) { + int digitsum = findDigitSum( n ) ; + std::vector<int> primeFactors = primeFactorize( n ) ; + std::map<int , int> factorCount ; + for ( auto fac : primeFactors ) + factorCount[ fac ]++ ; + int factorSum = 0 ; + for ( auto & p : factorCount ) + factorSum += findDigitSum( p.first ) * p.second ; + return factorSum == digitsum ; +} + +int main( ) { + std::vector<int> smithNumbers ; + int current = 0 ; + while ( smithNumbers.size( ) < 10 ) { + current++ ; + if ( ( isComposite( current ) ) && ( isSmithNumber( current ) ) ) + smithNumbers.push_back( current ) ; + } + std::copy( smithNumbers.begin( ) , smithNumbers.end( ) , + std::ostream_iterator<int>( std::cout , " " )) ; + std::cout << std::endl ; + return 0 ; +} diff --git a/challenge-133/ulrich-rieke/haskell/ch-1.hs b/challenge-133/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..9155f95552 --- /dev/null +++ b/challenge-133/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,9 @@ +module Challenge133 + where + +solution :: Int -> Int +solution n = fst lastElement +where + lastElement :: ( Int , Int ) + lastElement = last $ takeWhile ( ( <= n ) . snd ) $ map (\i -> ( i , i ^ 2 ) ) + [0 .. n] diff --git a/challenge-133/ulrich-rieke/perl/ch-1.pl b/challenge-133/ulrich-rieke/perl/ch-1.pl new file mode 100644 index 0000000000..a0d802ce14 --- /dev/null +++ b/challenge-133/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +my $N = $ARGV[ 0 ] ; +while ( $N !~ /\A\d+\z/ ) { + say "Please enter a positive integer!" ; + $N = <STDIN> ; + chomp $N ; +} +my $current = 0 ; +while ( $current * $current < $N ) { + $current++ ; +} +if ( $current * $current == $N ) { + say $current ; +} +else { + say --$current ; +} diff --git a/challenge-133/ulrich-rieke/perl/ch-2.pl b/challenge-133/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..fafdf78650 --- /dev/null +++ b/challenge-133/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,97 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +sub findDivisors { + my $num = shift ; + my @divisors ; + for my $n ( 1 .. $num ) { + if ( ($num % $n ) == 0 ) { + push @divisors , $n ; + } + } + return @divisors ; +} + +sub isPrime { + my $num = shift ; + if ( $num == 1 ) { + return 0 ; + } + my @divisors = findDivisors( $num ) ; + if ( ($divisors[0] == 1) && ($divisors[1] == $num) ) { + return 1 ; + } + else { + return 0 ; + } +} + +sub isComposite { + my $number = shift ; + if ( (not ( isPrime( $number ) )) && ( $number != 1 ) ) { + return 1 ; + } + else { + return 0 ; + } +} + +sub prime_factorialize { + my $number = shift ; + my @primenumbers ; + my $current = 2 ; + while ( $number != 1 ) { + if ( ($number % $current) == 0 ) { + $number /= $current ; + push @primenumbers, $current ; + } + else { + do { + $current++ ; + } while ( not ( isPrime( $current ) ) ) ; + } + } + return @primenumbers ; +} + +sub toDigitSum { + my $number = shift ; + if ( $number < 10 ) { + return $number ; + } + else { + my $sum = 0 ; + map { $sum += $_ } split( // , $number ) ; + return $sum ; + } +} + +sub isSmithNumber { + my $num = shift ; + my $digitsum = toDigitSum( $num ) ; + my @primefactors = prime_factorialize( $num ) ; + my %factorCount ; + map { $factorCount{$_}++ } @primefactors ; + my $factorSum = 0 ; + for my $key ( keys %factorCount ) { + $factorSum += ( toDigitSum( $key ) * $factorCount{ $key } ) ; + } + if ( $factorSum == $digitsum ) { + return 1 ; + } + else { + return 0 ; + } +} + +my @smithNumbers ; +my $current = 0 ; +while ( scalar( @smithNumbers ) < 10 ) { + $current++ ; + if ( ( isComposite( $current )) && ( isSmithNumber( $current ) ) ) { + push @smithNumbers, $current ; + } +} +say join( ", " , @smithNumbers ) ; diff --git a/challenge-133/ulrich-rieke/raku/ch-1.raku b/challenge-133/ulrich-rieke/raku/ch-1.raku new file mode 100644 index 0000000000..883fff3551 --- /dev/null +++ b/challenge-133/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,9 @@ +use v6 ; + +sub MAIN( Int $N is copy ) { + my Int $current = 0 ; + repeat { + $current++ ; + } until ( $current * $current > $N ) ; + say --$current ; +} diff --git a/challenge-133/ulrich-rieke/raku/ch-2.raku b/challenge-133/ulrich-rieke/raku/ch-2.raku new file mode 100644 index 0000000000..3564eea2bc --- /dev/null +++ b/challenge-133/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,53 @@ +use v6 ; + +sub prime-factorize( Int $n is copy ) { + my @primeFactors = ( ) ; + my $current = 2 ; + while ( $n != 1 ) { + if ( $n %% $current ) { + $n div= $current ; + @primeFactors.push( $current ) ; + } + else { + repeat { + $current++ ; + } until ( $current.is-prime ) ; + } + } + return @primeFactors ; +} + +sub isComposite( Int $n is copy --> Bool ) { + return ( (not $n.is-prime) && ($n != 1 ) ) ; +} + +sub toDigitSum( Int $s is copy --> Int ) { + if ( $s < 10 ) { + return $s ; + } + else { + return [+] (~$s).comb.map( {.Int} ) ; + } +} + +sub isSmithNumber( Int $d is copy --> Bool) { + my $digitsum = toDigitSum( $d ) ; + my @primeFactors = prime-factorize( $d ) ; + my %factorCount ; + @primeFactors.map( { %factorCount{$_}++ } ) ; + my $factorSum ; + for %factorCount.kv -> $key , $value { + $factorSum += (toDigitSum( +$key ) * $value ) ; + } + return ($factorSum == $digitsum) ; +} + +my @smithNumbers = ( ) ; +my Int $current = 0 ; +while ( @smithNumbers.elems < 10 ) { + $current++ ; + if ( ( isComposite( $current ) ) && isSmithNumber( $current ) ) { + @smithNumbers.push( $current ) ; + } +} +say @smithNumbers.join( ", ") ; diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 5f5b1919ad..aa94390362 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,56 +1,62 @@ { - "title" : { - "text" : "The Weekly Challenge - 133" + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "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" }, "plotOptions" : { "series" : { - "borderWidth" : 0, "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - } + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 } }, - "legend" : { - "enabled" : 0 - }, - "chart" : { - "type" : "column" + "subtitle" : { + "text" : "[Champions: 10] Last updated at 2021-10-05 17:54:36 GMT" }, "series" : [ { "name" : "The Weekly Challenge - 133", - "colorByPoint" : 1, "data" : [ { - "name" : "Abigail", + "y" : 2, "drilldown" : "Abigail", - "y" : 2 + "name" : "Abigail" }, { "name" : "Andinus", - "y" : 2, - "drilldown" : "Andinus" + "drilldown" : "Andinus", + "y" : 2 }, { + "name" : "Ben Davies", "drilldown" : "Ben Davies", - "y" : 2, - "name" : "Ben Davies" + "y" : 2 }, { + "drilldown" : "Cheok-Yin Fung", "name" : "Cheok-Yin Fung", - "y" : 1, - "drilldown" : "Cheok-Yin Fung" + "y" : 1 }, { - "drilldown" : "James Raspass", "y" : 2, - "name" : "James Raspass" + "name" : "James Raspass", + "drilldown" : "James Raspass" }, { - "drilldown" : "James Smith", "y" : 2, - "name" : "James Smith" + "name" : "James Smith", + "drilldown" : "James Smith" }, { "y" : 2, @@ -58,31 +64,41 @@ "name" : "Mark Anderson" }, { - "drilldown" : "Peter Campbell Smith", "y" : 2, - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "drilldown" : "Peter Campbell Smith" }, { + "name" : "Roger Bell_West", "drilldown" : "Roger Bell_West", + "y" : 4 + }, + { "y" : 4, - "name" : "Roger Bell_West" + "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke" } - ] + ], + "colorByPoint" : 1 } ], + "xAxis" : { + "type" : "category" + }, "drilldown" : { "series" : [ { - "id" : "Abigail", + "name" : "Abigail", "data" : [ [ "Perl", 2 ] ], - "name" : "Abigail" + "id" : "Abigail" }, { + "id" : "Andinus", "data" : [ [ "Raku", @@ -93,71 +109,83 @@ 1 ] ], - "id" : "Andinus", "name" : "Andinus" }, { + "id" : "Ben Davies", + "name" : "Ben Davies", "data" : [ [ "Raku", 2 ] - ], - "id" : "Ben Davies", - "name" : "Ben Davies" + ] }, { + "id" : "Cheok-Yin Fung", "name" : "Cheok-Yin Fung", "data" : [ [ "Perl", 1 ] - ], - "id" : "Cheok-Yin Fung" + ] }, { + "id" : "James Raspass", "name" : "James Raspass", "data" : [ [ "Raku", 2 ] - ], - "id" : "James Raspass" + ] }, { + "id" : "James Smith", "name" : "James Smith", "data" : [ [ "Perl", 2 ] - ], - "id" : "James Smith" + ] }, { - "name" : "Mark Anderson", "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ] + ], + "name" : "Mark Anderson" }, { - "id" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", "data" : [ [ "Perl", 2 ] ], - "name" : "Peter Campbell Smith" + "id" : "Peter Campbell Smith" + }, + { + "name" : "Roger Bell_West", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Roger Bell_West" }, { - "id" : "Roger Bell_West", "data" : [ [ "Perl", @@ -168,24 +196,15 @@ 2 ] ], - "name" : "Roger Bell_West" + "name" : "Ulrich Rieke", + "id" : "Ulrich Rieke" } ] }, - "subtitle" : { - "text" : "[Champions: 9] Last updated at 2021-10-05 16:20:33 GMT" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "xAxis" : { - "type" : "category" + "title" : { + "text" : "The Weekly Challenge - 133" }, - "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/>" + "legend" : { + "enabled" : 0 } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 5014760b93..67fb939d69 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,24 +1,6 @@ { - "xAxis" : { - "type" : "category", - "labels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - } - } - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, "subtitle" : { - "text" : "Last updated at 2021-10-05 16:20:33 GMT" - }, - "yAxis" : { - "title" : { - "text" : null - }, - "min" : 0 + "text" : "Last updated at 2021-10-05 17:54:36 GMT" }, "series" : [ { @@ -29,24 +11,24 @@ ], [ "Perl", - 6309 + 6311 ], [ "Raku", - 3871 + 3873 ] ], "dataLabels" : { + "y" : 10, + "align" : "right", "rotation" : -90, + "format" : "{point.y:.0f}", "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" }, - "enabled" : "true", - "align" : "right", - "format" : "{point.y:.0f}", - "y" : 10, - "color" : "#FFFFFF" + "color" : "#FFFFFF", + "enabled" : "true" }, "name" : "Contributions" } @@ -54,9 +36,27 @@ "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2021]" }, + "xAxis" : { + "type" : "category", + "labels" : { + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + } + } + }, "legend" : { "enabled" : "false" }, + "yAxis" : { + "min" : 0, + "title" : { + "text" : null + } + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, "chart" : { "type" : "column" } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 108a251b8c..4ddeebcea8 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,16 +1,35 @@ { - "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2021-10-05 16:20:33 GMT" + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } + } + }, + "tooltip" : { + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", + "followPointer" : "true", + "headerFormat" : "<span style=\"font-size:11px\"></span>" + }, + "chart" : { + "type" : "column" }, "yAxis" : { "title" : { "text" : "Total Solutions" } }, + "legend" : { + "enabled" : "false" + }, + "xAxis" : { + "type" : "category" + }, "drilldown" : { "series" : [ { - "id" : "001", "data" : [ [ "Perl", @@ -25,9 +44,11 @@ 11 ] ], - "name" : "001" + "name" : "001", + "id" : "001" }, { + "id" : "002", "data" : [ [ "Perl", @@ -42,11 +63,9 @@ 10 ] ], - "id" : "002", "name" : "002" }, { - "name" : "003", "id" : "003", "data" : [ [ @@ -61,10 +80,12 @@ "Blog", 9 ] - ] + ], + "name" : "003" }, { "id" : "004", + "name" : "004", "data" : [ [ "Perl", @@ -78,11 +99,10 @@ "Blog", 10 ] - ], - "name" : "004" + ] }, { - "name" : "005", + "id" : "005", "data" : [ [ "Perl", @@ -97,7 +117,7 @@ 12 ] ], - "id" : "005" + "name" : "005" }, { "id" : "006", @@ -118,8 +138,8 @@ "name" : "006" }, { - "name" : "007", "id" : "007", + "name" : "007", "data" : [ [ "Perl", @@ -136,6 +156,7 @@ ] }, { + "id" : "008", "data" : [ [ "Perl", @@ -150,11 +171,10 @@ 12 ] ], - "id" : "008", "name" : "008" }, { - "name" : "009", + "id" : "009", "data" : [ [ "Perl", @@ -169,7 +189,7 @@ 13 ] ], - "id" : "009" + "name" : "009" }, { "data" : [ @@ -186,10 +206,11 @@ 11 ] ], - "id" : "010", - "name" : "010" + "name" : "010", + "id" : "010" }, { + "id" : "011", "data" : [ [ "Perl", @@ -204,11 +225,10 @@ 10 ] ], - "id" : "011", "name" : "011" }, { - "id" : "012", + "name" : "012", "data" : [ [ "Perl", @@ -223,10 +243,10 @@ 11 ] ], - "name" : "012" + "id" : "012" }, { - "name" : "013", + "id" : "013", "data" : [ [ "Perl", @@ -241,9 +261,10 @@ 13 ] ], - "id" : "013" + "name" : "013" }, { + "id" : "014", "data" : [ [ "Perl", @@ -258,11 +279,9 @@ 15 ] ], - "id" : "014", "name" : "014" }, { - "id" : "015", "data" : [ [ "Perl", @@ -277,11 +296,11 @@ 15 ] ], - "name" : "015" + "name" : "015", + "id" : "015" }, { "name" : "016", - "id" : "016", "data" : [ [ "Perl", @@ -295,7 +314,8 @@ "Blog", 12 ] - ] + ], + "id" : "016" }, { "id" : "017", @@ -316,8 +336,6 @@ "name" : "017" }, { - "name" : "018", - "id" : "018", "data" : [ [ "Perl", @@ -331,10 +349,11 @@ "Blog", 14 ] - ] + ], + "name" : "018", + "id" : "018" }, { - "name" : "019", "data" : [ [ "Perl", @@ -349,9 +368,11 @@ 13 ] ], + "name" : "019", "id" : "019" }, { + "name" : "020", "data" : [ [ "Perl", @@ -366,11 +387,9 @@ 13 ] ], - "id" : "020", - "name" : "020" + "id" : "020" }, { - "id" : "021", "data" : [ [ "Perl", @@ -385,9 +404,12 @@ 10 ] ], - "name" : "021" + "name" : "021", + "id" : "021" }, { + "id" : "022", + "name" : "022", "data" : [ [ "Perl", @@ -401,9 +423,7 @@ "Blog", 10 ] - ], - "id" : "022", - "name" : "022" + ] }, { "id" : "023", @@ -456,12 +476,11 @@ 12 ] ], - "id" : "025", - "name" : "025" + "name" : "025", + "id" : "025" }, { "name" : "026", - "id" : "026", "data" : [ [ "Perl", @@ -475,9 +494,11 @@ "Blog", 10 ] - ] + ], + "id" : "026" }, { + "name" : "027", "data" : [ [ "Perl", @@ -492,11 +513,10 @@ 9 ] ], - "id" : "027", - "name" : "027" + "id" : "027" }, { - "id" : "028", + "name" : "028", "data" : [ [ "Perl", @@ -511,9 +531,10 @@ 9 ] ], - "name" : "028" + "id" : "028" }, { + "id" : "029", "name" : "029", "data" : [ [ @@ -528,8 +549,7 @@ "Blog", 12 ] - ], - "id" : "029" + ] }, { "id" : "030", @@ -568,6 +588,7 @@ "id" : "031" }, { + "id" : "032", "name" : "032", "data" : [ [ |
