diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-02 22:11:43 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-02 22:11:43 +0100 |
| commit | 25b6f89a6bbb4860b072d2f20ab72d6f4e4aa57d (patch) | |
| tree | 6c76cce36b5db283bc17c8e041453c8852c32d9b | |
| parent | 5700092f38ceae57dc000f4f9538207779dcf643 (diff) | |
| download | perlweeklychallenge-club-25b6f89a6bbb4860b072d2f20ab72d6f4e4aa57d.tar.gz perlweeklychallenge-club-25b6f89a6bbb4860b072d2f20ab72d6f4e4aa57d.tar.bz2 perlweeklychallenge-club-25b6f89a6bbb4860b072d2f20ab72d6f4e4aa57d.zip | |
- Added solutions by Ulrich Rieke.
- Added solutions by Paulo Custodio.
- Added solutions by David Ferrone.
- Added solutions by W. Luis Mochan.
32 files changed, 2616 insertions, 2322 deletions
diff --git a/challenge-285/ulrich-rieke/cpp/ch-1.cpp b/challenge-285/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..5055130792 --- /dev/null +++ b/challenge-285/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,40 @@ +#include <iostream>
+#include <string>
+#include <sstream>
+#include <algorithm>
+#include <vector>
+#include <iterator>
+
+std::vector<std::string> split( std::string text , const char delimiter ) {
+ std::istringstream istr { text } ;
+ std::vector<std::string> tokens ;
+ std::string word ;
+ while ( std::getline( istr , word , delimiter ))
+ tokens.push_back( word ) ;
+ return tokens ;
+}
+
+int main( ) {
+ std::cout << "Enter some routes, separated by comma!\n" ;
+ std::cout << "For every route, separate start and destination by blank!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> routes { split( line, ',' ) } ;
+ std::vector<std::vector<std::string>> allRoutes ;
+ std::vector<std::string> starts ;//for all start fields
+ for ( auto route : routes ) {
+ auto routepair = split( route , ' ' ) ;//first vector is start , then end
+ allRoutes.push_back( routepair ) ;
+ starts.push_back( routepair[0] ) ;//append start to collection of starts
+ }
+ std::vector<std::string> solution ;
+ for ( auto p : allRoutes ) {
+ if ( std::find( starts.begin( ) , starts.end( ) , p[1] ) ==
+ starts.end( ) ) //destination not found in starts
+ solution.push_back( p[1] ) ;//so part of solutin
+ }
+ std::copy( solution.begin( ) , solution.end( ) ,
+ std::ostream_iterator<std::string>( std::cout , " " ) ) ;
+ std::cout << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-285/ulrich-rieke/cpp/ch-2.cpp b/challenge-285/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..e68be4c870 --- /dev/null +++ b/challenge-285/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,26 @@ +#include <iostream>
+
+int main( ) {
+ int amount ;
+ std::cout << "Enter an amount of money in pennies!\n" ;
+ std::cin >> amount ;
+ int combis = 0 ;
+ for (int pennies = 0 ; pennies < amount + 1 ; pennies++ ) {
+ for ( int nickels = 0 ; nickels < (amount / 5 ) + 1 ; nickels++ ) {
+ for ( int dimes = 0 ; dimes < ( amount / 10 ) + 1 ; dimes++ ) {
+ for ( int quarters = 0 ; quarters < ( amount / 25 ) + 1 ;
+ quarters++ ) {
+ for ( int half_dollars = 0 ; half_dollars < ( amount / 50 )
+ + 1 ; half_dollars++ ) {
+ if ( pennies + nickels * 5 + dimes * 10 +
+ quarters * 25 + half_dollars * 50 == amount )
+ combis++ ;
+ }
+ }
+ }
+ }
+ }
+ std::cout << combis << '\n' ;
+ return 0 ;
+}
+
diff --git a/challenge-285/ulrich-rieke/haskell/ch-1.hs b/challenge-285/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..0ddcd35d73 --- /dev/null +++ b/challenge-285/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,19 @@ +module Challenge285
+ where
+import Data.List.Split ( splitOn )
+
+solution :: String -> String
+solution input =
+ let routes = splitOn "," input
+ routepairs = map (\li -> (head li , last li ) ) $ map ( concat .
+ splitOn " " ) routes
+ starts = map fst routepairs
+ destinations = map snd routepairs
+ in filter (\dest -> notElem dest starts ) destinations
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some routes, separated by ','!"
+ putStrLn "Separate start and destination by a blank!"
+ allRoutes <- getLine
+ print $ solution allRoutes
diff --git a/challenge-285/ulrich-rieke/haskell/ch-2.hs b/challenge-285/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..e17bc8f81f --- /dev/null +++ b/challenge-285/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,16 @@ +module Challenge285_2
+ where
+
+denominations :: [Int]
+denominations = [50, 25 , 10 , 5 , 1]
+
+findCoinCombis :: [Int] -> Int -> [[Int]]
+findCoinCombis [1] n = [[n]]
+findCoinCombis ( den:rest ) n = [c:cs | c <- [0..div n den] , cs <-
+ findCoinCombis rest ( n - c * den )]
+
+main :: IO ( )
+main = do
+ putStrLn "Enter an amount of money in pennies!"
+ amount <- getLine
+ print $ length $ findCoinCombis denominations $ read amount
diff --git a/challenge-285/ulrich-rieke/perl/ch-1.pl b/challenge-285/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..e66b2d5d88 --- /dev/null +++ b/challenge-285/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter some routes ( start and destination separated by blank)!" ;
+say "Enter routes by ','!" ;
+my $line = <STDIN> ;
+chomp( $line ) ;
+my @routes = split( /\,/ , $line ) ;
+my %routepairs ;
+for my $route ( @routes ) {
+ my ( $start , $destination ) = split( /\s/ , $route ) ;
+ $routepairs{$start} = $destination ;
+}
+say join( ',' , grep { not ( exists( $routepairs{$_} ) ) } values
+ %routepairs ) ;
diff --git a/challenge-285/ulrich-rieke/perl/ch-2.pl b/challenge-285/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..ef36e70a0d --- /dev/null +++ b/challenge-285/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use POSIX ;
+
+say "Enter an amount of money in pennies!" ;
+my $amount = <STDIN> ;
+chomp $amount ;
+my $combis = 0 ;
+for my $pennies( 0..$amount) {
+ for my $nickels( 0..floor( $amount / 5 ) ) {
+ for my $dimes( 0..floor( $amount / 10 ) ) {
+ for my $quarters( 0..floor( $amount / 25 ) ) {
+ for my $half_dollars( 0..floor( $amount / 50 ) ) {
+ if ( $pennies + $nickels * 5 + $dimes * 10 + $quarters * 25
+ + $half_dollars * 50 == $amount ) {
+ $combis++ ;
+ }
+ }
+ }
+ }
+ }
+}
+say $combis ;
diff --git a/challenge-285/ulrich-rieke/raku/ch-1.raku b/challenge-285/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..3dd8e08e78 --- /dev/null +++ b/challenge-285/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,12 @@ +use v6 ;
+
+say "Enter some routes, start and destination separated by blanks!" ;
+say "Separate routes by ','!" ;
+my $line = $*IN.get ;
+my @routes = $line.split( /','/ ) ;
+my %pairs ;
+for @routes -> $route {
+ my ($start , $destination) = $route.split( /\s/ ) ;
+ %pairs{$start} = $destination ;
+}
+say join( ',' , %pairs.values.grep( {not %pairs{$_}:exists } )) ;
diff --git a/challenge-285/ulrich-rieke/raku/ch-2.raku b/challenge-285/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..b6b7421d7b --- /dev/null +++ b/challenge-285/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,21 @@ +use v6 ;
+
+say "Enter an amount of money in cents!" ;
+my $line = $*IN.get ;
+my $amount = $line.Int ;
+my $combis = 0 ;
+for (0..$amount) -> $pennies {
+ for (0..$amount div 5 ) -> $nickels {
+ for (0..$amount div 10 ) -> $dimes {
+ for ( 0..$amount div 25) -> $quarters {
+ for ( 0..$amount div 50 ) -> $half-dollars {
+ if ($pennies + $nickels * 5 + $dimes * 10 +
+ $quarters * 25 + $half-dollars * 50 == $amount ) {
+ $combis++ ;
+ }
+ }
+ }
+ }
+ }
+}
+say $combis ;
diff --git a/challenge-285/ulrich-rieke/rust/ch-1.rs b/challenge-285/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..1de72ede46 --- /dev/null +++ b/challenge-285/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,21 @@ +use std::io ; + +fn main() { + println!("Enter some routes!"); + println!("Enter start and destination by blank, routes by ','!" ) ; + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = inline.as_str( ).trim( ) ; + let routes : Vec<&str> = entered_line.split( ",").collect( ) ; + let pairs : Vec<Vec<&str>> = routes.iter( ).map( | s | + s.split_whitespace( ).collect( ) ).collect( ) ; + let mut solution : Vec<&str> = Vec::new( ) ; + for p in &pairs { + let destination = p[1] ; + if pairs.iter( ).filter( | &a_pair | a_pair[0] == destination ). + count( ) == 0 { + solution.push( destination ) ; + } + } + println!("{:?}" , solution ) ; +} diff --git a/challenge-285/ulrich-rieke/rust/ch-2.rs b/challenge-285/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..fa78414e07 --- /dev/null +++ b/challenge-285/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,25 @@ +use std::io ; + +fn main() { + println!("Enter an amount of money in cents!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = inline.as_str().trim( ) ; + let amount : u32 = entered_line.parse::<u32>( ).unwrap( ) ; + let mut combis : u64 = 0 ; + for pennies in 0..=amount { + for nickels in 0..=amount/5 { + for dimes in 0..=amount / 10 { + for quarters in 0..=amount / 25 { + for half_dollars in 0..=amount / 50 { + if pennies + nickels * 5 + dimes * 10 + quarters * 25 + + half_dollars * 50 == amount { + combis += 1 ; + } + } + } + } + } + } + println!("{}" , combis ) ; +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index fb0a273c30..2ea0b4c4c0 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,24 +1,100 @@ { + "plotOptions" : { + "series" : { + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + }, + "borderWidth" : 0 + } + }, + "chart" : { + "type" : "column" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "legend" : { + "enabled" : 0 + }, "subtitle" : { - "text" : "[Champions: 4] Last updated at 2024-09-02 12:06:32 GMT" + "text" : "[Champions: 8] Last updated at 2024-09-02 21:11:31 GMT" }, "xAxis" : { "type" : "category" }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } + "series" : [ + { + "name" : "The Weekly Challenge - 285", + "colorByPoint" : 1, + "data" : [ + { + "drilldown" : "Ali Moradi", + "y" : 3, + "name" : "Ali Moradi" + }, + { + "name" : "David Ferrone", + "y" : 3, + "drilldown" : "David Ferrone" + }, + { + "y" : 2, + "name" : "E. Choroba", + "drilldown" : "E. Choroba" + }, + { + "drilldown" : "Feng Chang", + "name" : "Feng Chang", + "y" : 2 + }, + { + "drilldown" : "Mark Anderson", + "name" : "Mark Anderson", + "y" : 2 + }, + { + "drilldown" : "Paulo Custodio", + "name" : "Paulo Custodio", + "y" : 2 + }, + { + "drilldown" : "Ulrich Rieke", + "y" : 4, + "name" : "Ulrich Rieke" + }, + { + "y" : 3, + "name" : "W. Luis Mochan", + "drilldown" : "W. Luis Mochan" + } + ] } + ], + "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/>" }, "drilldown" : { "series" : [ { - "name" : "Ali Moradi", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], "id" : "Ali Moradi", + "name" : "Ali Moradi" + }, + { "data" : [ [ "Perl", @@ -28,85 +104,81 @@ "Blog", 1 ] - ] + ], + "id" : "David Ferrone", + "name" : "David Ferrone" }, { - "name" : "E. Choroba", + "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] ], - "id" : "E. Choroba" + "name" : "E. Choroba" }, { - "name" : "Feng Chang", "data" : [ [ "Raku", 2 ] ], - "id" : "Feng Chang" + "id" : "Feng Chang", + "name" : "Feng Chang" }, { - "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] ], + "id" : "Mark Anderson", "name" : "Mark Anderson" + }, + { + "name" : "Paulo Custodio", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Paulo Custodio" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke" + }, + { + "id" : "W. Luis Mochan", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "W. Luis Mochan" } ] }, - "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/>" - }, "title" : { "text" : "The Weekly Challenge - 285" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "chart" : { - "type" : "column" - }, - "legend" : { - "enabled" : 0 - }, - "series" : [ - { - "data" : [ - { - "name" : "Ali Moradi", - "drilldown" : "Ali Moradi", - "y" : 3 - }, - { - "y" : 2, - "name" : "E. Choroba", - "drilldown" : "E. Choroba" - }, - { - "y" : 2, - "drilldown" : "Feng Chang", - "name" : "Feng Chang" - }, - { - "name" : "Mark Anderson", - "drilldown" : "Mark Anderson", - "y" : 2 - } - ], - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 285" - } - ] + } } diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index b309687867..e3ad5f00af 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -1,154 +1,142 @@ { - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "chart" : { - "type" : "column" - }, - "legend" : { - "enabled" : "false" - }, "series" : [ { - "name" : "The Weekly Challenge Languages", "colorByPoint" : "true", "data" : [ { - "name" : "041", "drilldown" : "041", + "name" : "041", "y" : 80 }, { - "drilldown" : "040", "name" : "040", - "y" : 77 + "y" : 77, + "drilldown" : "040" }, { "name" : "039", - "drilldown" : "039", - "y" : 68 + "y" : 68, + "drilldown" : "039" }, { - "y" : 74, + "drilldown" : "038", "name" : "038", - "drilldown" : "038" + "y" : 74 }, { - "name" : "037", "drilldown" : "037", - "y" : 70 + "y" : 70, + "name" : "037" }, { - "y" : 70, "drilldown" : "036", + "y" : 70, "name" : "036" }, { - "name" : "035", "drilldown" : "035", + "name" : "035", "y" : 68 }, { - "drilldown" : "034", "name" : "034", - "y" : 70 + "y" : 70, + "drilldown" : "034" }, { - "name" : "033", "drilldown" : "033", - "y" : 113 + "y" : 113, + "name" : "033" }, { - "name" : "032", "drilldown" : "032", - "y" : 97 + "y" : 97, + "name" : "032" }, { - "drilldown" : "031", "name" : "031", - "y" : 93 + "y" : 93, + "drilldown" : "031" }, { + "y" : 120, "name" : "030", - "drilldown" : "030", - "y" : 120 + "drilldown" : "030" }, { + "name" : "029", "y" : 83, - "drilldown" : "029", - "name" : "029" + "drilldown" : "029" }, { - "y" : 82, "name" : "028", + "y" : 82, "drilldown" : "028" }, { - "y" : 64, "drilldown" : "027", - "name" : "027" + "name" : "027", + "y" : 64 }, { - "drilldown" : "026", + "y" : 75, "name" : "026", - "y" : 75 + "drilldown" : "026" }, { - "drilldown" : "025", "name" : "025", - "y" : 62 + "y" : 62, + "drilldown" : "025" }, { - "name" : "024", "drilldown" : "024", + "name" : "024", "y" : 77 }, { "drilldown" : "023", - "name" : "023", - "y" : 88 + "y" : 88, + "name" : "023" }, { + "drilldown" : "022", "y" : 72, - "name" : "022", - "drilldown" : "022" + "name" : "022" }, { - "drilldown" : "021", "name" : "021", - "y" : 72 + "y" : 72, + "drilldown" : "021" }, { + "y" : 100, "name" : "020", - "drilldown" : "020", - "y" : 100 + "drilldown" : "020" }, { + "drilldown" : "019", "y" : 101, - "name" : "019", - "drilldown" : "019" + "name" : "019" }, { "name" : "018", - "drilldown" : "018", - "y" : 82 + "y" : 82, + "drilldown" : "018" }, { - "name" : "017", "drilldown" : "017", + "name" : "017", "y" : 83 }, { + "name" : "016", "y" : 75, - "drilldown" : "016", - "name" : "016" + "drilldown" : "016" }, { "drilldown" : "015", - "name" : "015", - "y" : 95 + "y" : 95, + "name" : "015" }, { "drilldown" : "014", @@ -161,44 +149,44 @@ "drilldown" : "013" }, { - "name" : "012", "drilldown" : "012", - "y" : 90 + "y" : 90, + "name" : "012" }, { - "name" : "011", "drilldown" : "011", - "y" : 86 + "y" : 86, + "name" : "011" }, { - "drilldown" : "010", "name" : "010", - "y" : 69 + "y" : 69, + "drilldown" : "010" }, { - "y" : 79, "drilldown" : "009", - "name" : "009" + "name" : "009", + "y" : 79 }, { - "drilldown" : "008", "name" : "008", - "y" : 82 + "y" : 82, + "drilldown" : "008" }, { - "name" : "007", "drilldown" : "007", + "name" : "007", "y" : 71 }, { "y" : 63, - "drilldown" : "006", - "name" : "006" + "name" : "006", + "drilldown" : "006" }, { "y" : 82, - "drilldown" : "005", - "name" : "005" + "name" : "005", + "drilldown" : "005" }, { "y" : 106, @@ -206,26 +194,24 @@ "drilldown" : "004" }, { - "y" : 91, "name" : "003", + "y" : 91, "drilldown" : "003" }, { + "drilldown" : "002", "y" : 133, - "name" : "002", - "drilldown" : "002" + "name" : "002" }, { "drilldown" : "001", "name" : "001", "y" : 165 } - ] + ], + "name" : "The Weekly Challenge Languages" } ], - "xAxis" : { - "type" : "category" - }, "drilldown" : { "series" : [ { @@ -283,6 +269,8 @@ "name" : "039" }, { + "name" : "038", + "id" : "038", "data" : [ [ "Perl", @@ -296,11 +284,11 @@ "Blog", 12 ] - ], - "id" : "038", - "name" : "038" + ] }, { + "name" : "037", + "id" : "037", "data" : [ [ "Perl", @@ -314,9 +302,7 @@ "Blog", 9 ] - ], - "id" : "037", - "name" : "037" + ] }, { "name" : "036", @@ -337,8 +323,6 @@ ] }, { - |
