diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-01-12 11:56:55 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-01-12 11:56:55 +0000 |
| commit | eb4ccd1d13b390f36d35102d0630e636caa6e74d (patch) | |
| tree | 88c7f4363649c1d3034de5762ab2d3fedecc3ef5 | |
| parent | d996cdb57ab2b895ea8600ebf3c404972735db26 (diff) | |
| download | perlweeklychallenge-club-eb4ccd1d13b390f36d35102d0630e636caa6e74d.tar.gz perlweeklychallenge-club-eb4ccd1d13b390f36d35102d0630e636caa6e74d.tar.bz2 perlweeklychallenge-club-eb4ccd1d13b390f36d35102d0630e636caa6e74d.zip | |
- Added solutions by Ulrich Rieke.
| -rw-r--r-- | challenge-147/ulrich-rieke/cpp/ch-1.cpp | 46 | ||||
| -rw-r--r-- | challenge-147/ulrich-rieke/haskell/ch-1.hs | 24 | ||||
| -rw-r--r-- | challenge-147/ulrich-rieke/perl/ch-2.pl | 42 | ||||
| -rw-r--r-- | challenge-147/ulrich-rieke/raku/ch-1.raku | 31 | ||||
| -rw-r--r-- | stats/pwc-current.json | 123 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 66 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 998 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 726 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 44 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 98 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 54 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 100 | ||||
| -rw-r--r-- | stats/pwc-summary-211-240.json | 112 | ||||
| -rw-r--r-- | stats/pwc-summary-241-270.json | 64 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 30 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 36 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 34 |
18 files changed, 1418 insertions, 1256 deletions
diff --git a/challenge-147/ulrich-rieke/cpp/ch-1.cpp b/challenge-147/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..975ba98215 --- /dev/null +++ b/challenge-147/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,46 @@ +#include <iostream> +#include <string> +#include <cmath> +#include <vector> + +bool isPrime( int n ) { + if ( n == 1 ) + return false ; + if ( n == 2 ) + return true ; + int root = static_cast<int>( floor( sqrt( static_cast<double>( n ) ))) ; + for ( int i = 2 ; i < root + 1 ; i++ ) + if ( n % i == 0 ) + return false ; + return true ; +} + +bool isLeftTruncatablePrime( int n ) { + if ( ! isPrime( n ) ) + return false ; + std::string numberstring( std::to_string( n ) ) ; + auto found = numberstring.find( '0' ) ; + if ( found != std::string::npos ) + return false ; + int len = static_cast<int>(numberstring.length( ) ) ; + for ( int i = 0 ; i < len ; i++ ) { + int num = std::stoi( numberstring.substr( i ) ) ; + if ( ! isPrime( num ) ) + return false ; + } + return true ; +} + +int main( ) { + std::vector<int> leftTruncatables ; + int current = 0 ; + while ( leftTruncatables.size( ) < 20 ) { + current++ ; + if ( isLeftTruncatablePrime( current ) ) + leftTruncatables.push_back( current ) ; + } + for ( int i : leftTruncatables ) + std::cout << i << ' ' ; + std::cout << std::endl ; + return 0 ; +} diff --git a/challenge-147/ulrich-rieke/haskell/ch-1.hs b/challenge-147/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..6c3dec240b --- /dev/null +++ b/challenge-147/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,24 @@ +module Challenge147 + where + +isPrime :: Int -> Bool +isPrime n + |n == 1 = False + |n == 2 = True + |otherwise = null $ filter (\i -> mod n i == 0 ) [2 .. root] + where + root :: Int + root = round $ sqrt $ fromIntegral n + +isTruncatablePrime :: Int -> Bool +isTruncatablePrime n = (not $ elem '0' nstring) && all isPrime theList + where + l :: Int + l = length nstring + nstring :: String + nstring = show n + theList :: [Int] + theList = map (\i -> read $ drop i nstring) [0 .. l - 1] + +solution :: [Int] +solution = take 20 $ filter isTruncatablePrime [1 , 2 ..] diff --git a/challenge-147/ulrich-rieke/perl/ch-2.pl b/challenge-147/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..3267c431cf --- /dev/null +++ b/challenge-147/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use Algorithm::Combinatorics qw ( combinations ) ; +use POSIX ; +use feature 'say' ; + +sub isPentagonNumber { + my $num = shift ; + my $root = ( sqrt( 24 * $num + 1 ) + 1 ) / 2 ; + return floor( $root ) == $root ; +} + +sub toPentagon { + my $num = shift ; + return ( $num * ( 3 * $num - 1 )) / 2 ; +} + +my @pentagons = (1, 5, 12, 22, 35, 51, 70, 92, 117 , 145 ) ; +my $current = 10 ; +my $iter = combinations( \@pentagons, 2 ) ; +while ( my $c = $iter->next ) { + if ( isPentagonNumber( $c->[ 0 ] + $c->[1] ) && + isPentagonNumber( abs( $c->[0] - $c->[1] ) ) ) { + say "$c->[0] , $c->[1]" ; + exit( 0 ) ; + } +} +my $combiFound = 0 ; +do { + $current++ ; + push @pentagons , toPentagon( $current ) ; + $iter = combinations( \@pentagons , 2 ) ; + while ( my $c = $iter->next ) { + if ( isPentagonNumber( $c->[ 0 ] + $c->[1] ) && + isPentagonNumber( abs( $c->[0] - $c->[1] ) ) ) { + say "$c->[0] , $c->[1]" ; + $combiFound = 1 ; + last ; + } + } +} while ( $combiFound == 0 ) ; diff --git a/challenge-147/ulrich-rieke/raku/ch-1.raku b/challenge-147/ulrich-rieke/raku/ch-1.raku new file mode 100644 index 0000000000..d98f9d615e --- /dev/null +++ b/challenge-147/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,31 @@ +use v6 ; + +sub isTruncatablePrime( Int $n is copy --> Bool ) { + if ( ~$n ~~ /0/ ) { + return False ; + } + elsif ( not $n.is-prime ) { + return False ; + } + else { + while ( $n.is-prime ) { + if ( $n < 10 ) { + return True ; + } + else { + my $len = ~$n.chars ; + $n = $n % ( 10 ** ( $len - 1 ) ) ; + } + } + } +} + +my @truncatables ; +my $current = 1; +while ( @truncatables.elems < 20 ) { + $current++ ; + if ( isTruncatablePrime( $current ) ) { + @truncatables.push( $current ) ; + } +} +say @truncatables ; diff --git a/stats/pwc-current.json b/stats/pwc-current.json index cc7cd86cad..ae8c3c8e5f 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,35 +1,13 @@ { - "title" : { - "text" : "The Weekly Challenge - 147" - }, - "legend" : { - "enabled" : 0 - }, - "subtitle" : { - "text" : "[Champions: 9] Last updated at 2022-01-12 09:58:23 GMT" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "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 - }, "plotOptions" : { "series" : { "borderWidth" : 0, "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 + "enabled" : 1, + "format" : "{point.y}" } } }, - "chart" : { - "type" : "column" - }, "drilldown" : { "series" : [ { @@ -43,8 +21,6 @@ ] }, { - "id" : "James Smith", - "name" : "James Smith", "data" : [ [ "Perl", @@ -54,11 +30,11 @@ "Blog", 1 ] - ] + ], + "name" : "James Smith", + "id" : "James Smith" }, { - "id" : "Luca Ferrari", - "name" : "Luca Ferrari", "data" : [ [ "Raku", @@ -68,16 +44,18 @@ "Blog", 5 ] - ] + ], + "name" : "Luca Ferrari", + "id" : "Luca Ferrari" }, { - "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] ], + "name" : "Mark Anderson", "id" : "Mark Anderson" }, { @@ -96,6 +74,7 @@ }, { "id" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -105,10 +84,10 @@ "Blog", 1 ] - ], - "name" : "Peter Campbell Smith" + ] }, { + "id" : "Roger Bell_West", "data" : [ [ "Perl", @@ -123,17 +102,30 @@ 1 ] ], - "name" : "Roger Bell_West", - "id" : "Roger Bell_West" + "name" : "Roger Bell_West" }, { - "id" : "Simon Proctor", "name" : "Simon Proctor", "data" : [ [ "Raku", 2 ] + ], + "id" : "Simon Proctor" + }, + { + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ] ] }, { @@ -152,15 +144,28 @@ } ] }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "tooltip" : { + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "followPointer" : 1, + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>" + }, "xAxis" : { "type" : "category" }, + "title" : { + "text" : "The Weekly Challenge - 147" + }, "series" : [ { "data" : [ { - "name" : "Alexander Karelas", "drilldown" : "Alexander Karelas", + "name" : "Alexander Karelas", "y" : 1 }, { @@ -169,19 +174,19 @@ "name" : "James Smith" }, { - "drilldown" : "Luca Ferrari", "y" : 7, - "name" : "Luca Ferrari" + "name" : "Luca Ferrari", + "drilldown" : "Luca Ferrari" }, { + "y" : 2, "name" : "Mark Anderson", - "drilldown" : "Mark Anderson", - "y" : 2 + "drilldown" : "Mark Anderson" }, { "drilldown" : "Mohammad S Anwar", - "y" : 2, - "name" : "Mohammad S Anwar" + "name" : "Mohammad S Anwar", + "y" : 2 }, { "y" : 3, @@ -189,23 +194,37 @@ "name" : "Peter Campbell Smith" }, { + "name" : "Roger Bell_West", "drilldown" : "Roger Bell_West", - "y" : 5, - "name" : "Roger Bell_West" + "y" : 5 }, { - "name" : "Simon Proctor", + "y" : 2, "drilldown" : "Simon Proctor", - "y" : 2 + "name" : "Simon Proctor" + }, + { + "y" : 2, + "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke" }, { + "y" : 3, "name" : "W. Luis Mochan", - "drilldown" : "W. Luis Mochan", - "y" : 3 + "drilldown" : "W. Luis Mochan" } ], - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 147" + "name" : "The Weekly Challenge - 147", + "colorByPoint" : 1 } - ] + ], + "legend" : { + "enabled" : 0 + }, + "chart" : { + "type" : "column" + }, + "subtitle" : { + "text" : "[Champions: 10] Last updated at 2022-01-12 11:54:51 GMT" + } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 7ece9a7405..3f7d100cef 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,28 +1,31 @@ { + "yAxis" : { + "min" : 0, + "title" : { + "text" : null + } + }, "xAxis" : { - "type" : "category", "labels" : { "style" : { "fontSize" : "13px", "fontFamily" : "Verdana, sans-serif" } - } + }, + "type" : "category" + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2021]" + }, + "legend" : { + "enabled" : "false" }, "series" : [ { "name" : "Contributions", - "dataLabels" : { - "enabled" : "true", - "format" : "{point.y:.0f}", - "y" : 10, - "rotation" : -90, - "align" : "right", - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - }, - "color" : "#FFFFFF" - }, "data" : [ [ "Blog", @@ -30,34 +33,31 @@ ], [ "Perl", - 7067 + 7068 ], [ "Raku", - 4260 + 4261 ] - ] + ], + "dataLabels" : { + "color" : "#FFFFFF", + "format" : "{point.y:.0f}", + "rotation" : -90, + "y" : 10, + "enabled" : "true", + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + }, + "align" : "right" + } } ], "chart" : { "type" : "column" }, "subtitle" : { - "text" : "Last updated at 2022-01-12 09:58:23 GMT" - }, - "yAxis" : { - "title" : { - "text" : null - }, - "min" : 0 - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, - "legend" : { - "enabled" : "false" - }, - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2021]" + "text" : "Last updated at 2022-01-12 11:54:51 GMT" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index affa39cfaf..2dbe846b3c 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,9 +1,15 @@ { + "xAxis" : { + "type" : "category" + }, + "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>" + }, "drilldown" : { "series" : [ { - "id" : "001", - "name" : "001", "data" : [ [ "Perl", @@ -17,7 +23,9 @@ "Blog", 11 ] - ] + ], + "name" : "001", + "id" : "001" }, { "id" : "002", @@ -38,7 +46,6 @@ ] }, { - "name" : "003", "data" : [ [ "Perl", @@ -53,9 +60,12 @@ 9 ] ], + "name" : "003", "id" : "003" }, { + "id" : "004", + "name" : "004", "data" : [ [ "Perl", @@ -69,12 +79,9 @@ "Blog", 10 ] - ], - "name" : "004", - "id" : "004" + ] }, { - "id" : "005", "name" : "005", "data" : [ [ @@ -89,10 +96,11 @@ "Blog", 12 ] - ] + ], + "id" : "005" }, { - "id" : "006", + "name" : "006", "data" : [ [ "Perl", @@ -107,9 +115,10 @@ 7 ] ], - "name" : "006" + "id" : "006" }, { + "id" : "007", "data" : [ [ "Perl", @@ -124,12 +133,9 @@ 10 ] ], - "name" : "007", - "id" : "007" + "name" : "007" }, { - "id" : "008", - "name" : "008", "data" : [ [ "Perl", @@ -143,10 +149,11 @@ "Blog", 12 ] - ] + ], + "name" : "008", + "id" : "008" }, { - "id" : "009", "data" : [ [ "Perl", @@ -161,10 +168,10 @@ 13 ] ], - "name" : "009" + "name" : "009", + "id" : "009" }, { - "id" : "010", "data" : [ [ "Perl", @@ -179,11 +186,10 @@ 11 ] ], - "name" : "010" + "name" : "010", + "id" : "010" }, { - "id" : "011", - "name" : "011", "data" : [ [ "Perl", @@ -197,9 +203,12 @@ "Blog", 10 ] - ] + ], + "name" : "011", + "id" : "011" }, { + "name" : "012", "data" : [ [ "Perl", @@ -214,7 +223,6 @@ 11 ] ], - "name" : "012", "id" : "012" }, { @@ -255,6 +263,7 @@ }, { "id" : "015", + "name" : "015", "data" : [ [ "Perl", @@ -268,12 +277,9 @@ "Blog", 15 ] - ], - "name" : "015" + ] }, { - "id" : "016", - "name" : "016", "data" : [ [ "Perl", @@ -287,10 +293,11 @@ "Blog", 12 ] - ] + ], + "name" : "016", + "id" : "016" }, { - "name" : "017", "data" : [ [ "Perl", @@ -305,11 +312,10 @@ 12 ] ], + "name" : "017", "id" : "017" }, { - "id" : "018", - "name" : "018", "data" : [ [ "Perl", @@ -323,10 +329,11 @@ "Blog", 14 ] - ] + ], + "name" : "018", + "id" : "018" }, { - "name" : "019", "data" : [ [ "Perl", @@ -341,10 +348,10 @@ 13 ] ], + "name" : "019", "id" : "019" }, { - "id" : "020", "name" : "020", "data" : [ [ @@ -359,10 +366,10 @@ "Blog", 13 ] - ] + ], + "id" : "020" }, { - "name" : "021", "data" : [ [ "Perl", @@ -377,10 +384,10 @@ 10 ] ], + "name" : "021", "id" : "021" }, { - "name" : "022", "data" : [ [ "Perl", @@ -395,11 +402,11 @@ 10 ] ], + "name" : "022", "id" : "022" }, { "id" : "023", - "name" : "023", "data" : [ [ "Perl", @@ -413,7 +420,8 @@ "Blog", 12 ] - ] + ], + "name" : "023" }, { "id" : "024", @@ -434,6 +442,8 @@ ] }, { + "id" : "025", + "name" : "025", "data" : [ [ "Perl", @@ -447,12 +457,9 @@ "Blog", 12 ] - ], - "name" : "025", - "id" : "025" + ] }, { - "id" : "026", "data" : [ [ "Perl", @@ -467,7 +474,8 @@ 10 ] ], - "name" : "026" + "name" : "026", + "id" : "026" }, { "data" : [ @@ -488,8 +496,6 @@ "id" : "027" }, { - "id" : "028", - "name" : "028", "data" : [ [ "Perl", @@ -503,10 +509,11 @@ "Blog", 9 ] - ] + ], + "name" : "028", + "id" : "028" }, { - "id" : "029", "data" : [ [ "Perl", @@ -521,7 +528,8 @@ 12 ] ], - "name" : "029" + "name" : "029", + "id" : "029" }, { "data" : [ @@ -542,7 +550,7 @@ "id" : "030" }, { - "name" : "031", + "id" : "031", "data" : [ [ "Perl", @@ -557,10 +565,9 @@ 9 ] ], - "id" : "031" + "name" : "031" }, { - "id" : "032", "data" : [ [ "Perl", @@ -575,9 +582,12 @@ 10 ] ], - "name" : "032" + "name" : "032", + "id" : "032" }, { + "id" : "033", + "name" : "033", "data" : [ [ "Perl", @@ -591,9 +601,7 @@ "Blog", 10 ] - ], - "name" : "033", - "id" : "033" + ] }, { "id" : "034", @@ -615,7 +623,6 @@ }, { "id" : "035", - "name" : "035", "data" : [ [ "Perl", @@ -629,7 +636,8 @@ "Blog", 9 ] - ] + ], + "name" : "035" }, { "id" : "036", @@ -651,6 +659,7 @@ }, { "id" : "037", + "name" : "037", "data" : [ [ "Perl", @@ -664,11 +673,10 @@ "Blog", 9 ] - ], - "name" : "037" + ] }, { - "name" : "038", + "id" : "038", "data" : [ [ "Perl", @@ -683,11 +691,9 @@ 12 ] ], - "id" : "038" + "name" : "038" }, { - "id" : "039", - "name" : "039", "data" : [ [ "Perl", @@ -701,9 +707,12 @@ "Blog", 12 ] - ] + ], + "name" : "039", + "id" : "039" }, { + "name" : "040", "data" : [ [ "Perl", @@ -718,12 +727,9 @@ 10 ] ], - "name" : "040", "id" : "040" }, { - "id" : "041", - "name" : "041", "data" : [ [ "Perl", @@ -737,9 +743,12 @@ "Blog", 9 ] - ] + ], + "name" : "041", + "id" : "041" }, { + "id" : "042", "data" : [ [ "Perl", @@ -754,12 +763,10 @@ 11 ] ], - "name" : "042", - "id" : "042" + "name" : "042" }, { "id" : "043", - "name" : "043", "data" : [ [ "Perl", @@ -773,9 +780,11 @@ "Blog", 11 ] - ] + ], + "name" : "043" }, { + "id" : "044", "data" : [ [ "Perl", @@ -790,11 +799,9 @@ 11 ] ], - "name" : "044", - "id" : "044" + "name" : "044" }, { - "id" : "045", "name" : "045", "data" : [ [ @@ -809,7 +816,8 @@ "Blog", 11 ] - ] + ], + "id" : "045" }, { "name" : "046", @@ -830,6 +838,7 @@ "id" : "046" }, { + "name" : "047", "data" : [ [ "Perl", @@ -844,11 +853,10 @@ 10 ] ], - "name" : "047", "id" : "047" }, { - "id" : "048", + "name" : "048", "data" : [ [ "Perl", @@ -863,11 +871,10 @@ 12 ] ], - "name" : "048" + "id" : "048" }, { "id" : "049", - "name" : "049", "data" : [ [ "Perl", @@ -881,9 +888,12 @@ "Blog", |
