diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-06-16 22:04:21 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-06-16 22:04:21 +0100 |
| commit | 93412c7fa19e013c244e41e417def795f7aac313 (patch) | |
| tree | dbe6dd06c816981ffaa65c7ecf18568de4eb8c64 | |
| parent | da274437fe0c9f4c0cf45d83bda88e096bfb3763 (diff) | |
| download | perlweeklychallenge-club-93412c7fa19e013c244e41e417def795f7aac313.tar.gz perlweeklychallenge-club-93412c7fa19e013c244e41e417def795f7aac313.tar.bz2 perlweeklychallenge-club-93412c7fa19e013c244e41e417def795f7aac313.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Ulrich Rieke.
- Added solutions by Feng Chang.
- Added solutions by Mark Anderson.
- Added solutions by Andrew Shitov.
- Added solutions by Niels van Dijke.
- Added solutions by E. Choroba.
- Added solutions by PokGoPun.
- Added solutions by Ali Moradi.
- Added solutions by Andreas Mahnke.
- Added solutions by Peter Meszaros.
- Added solutions by David Ferrone.
- Added solutions by W. Luis Mochan.
- Added solutions by Thomas Kohler.
41 files changed, 948 insertions, 441 deletions
diff --git a/challenge-326/eric-cheung/python/ch-1.py b/challenge-326/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..e9b004ffaa --- /dev/null +++ b/challenge-326/eric-cheung/python/ch-1.py @@ -0,0 +1,10 @@ +
+from datetime import datetime
+
+## strDate = "2025-02-02" ## Example 1
+## strDate = "2025-04-10" ## Example 2
+strDate = "2025-09-07" ## Example 3
+
+objDate = datetime.strptime(strDate, "%Y-%m-%d").timetuple()
+
+print (objDate.tm_yday)
diff --git a/challenge-326/eric-cheung/python/ch-2.py b/challenge-326/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..347f9d2014 --- /dev/null +++ b/challenge-326/eric-cheung/python/ch-2.py @@ -0,0 +1,11 @@ +
+## arrInt = [1, 3, 2, 4] ## Example 1
+## arrInt = [1, 1, 2, 2] ## Example 2
+arrInt = [3, 1, 3, 2] ## Example 3
+
+arrOutput = []
+
+for nIndx in range(1, len(arrInt), 2):
+ arrOutput = arrOutput + [arrInt[nIndx]] * arrInt[nIndx - 1]
+
+print (arrOutput)
diff --git a/challenge-326/feng-chang/README.md b/challenge-326/feng-chang/README.md index 6d43a92a22..74e56de3ed 100644 --- a/challenge-326/feng-chang/README.md +++ b/challenge-326/feng-chang/README.md @@ -1,2 +1 @@ -# blog -* [PWC #217](https://seaker.github.io/jekyll/update/2023/05/16/PWC-217.html) +Solutions by Feng Chang. diff --git a/challenge-326/feng-chang/raku/ch-1.raku b/challenge-326/feng-chang/raku/ch-1.raku new file mode 100644 index 0000000000..637716a725 --- /dev/null +++ b/challenge-326/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $s); + +put $s.Date.day-of-year; diff --git a/challenge-326/feng-chang/raku/ch-2.raku b/challenge-326/feng-chang/raku/ch-2.raku new file mode 100644 index 0000000000..15baa6a610 --- /dev/null +++ b/challenge-326/feng-chang/raku/ch-2.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +put @ints.rotor(2).map({ .[1] xx .[0] }).flat; diff --git a/challenge-326/perlboy1967/perl/ch1.pl b/challenge-326/perlboy1967/perl/ch-1.pl index f194426bb6..f194426bb6 100755 --- a/challenge-326/perlboy1967/perl/ch1.pl +++ b/challenge-326/perlboy1967/perl/ch-1.pl diff --git a/challenge-326/perlboy1967/perl/ch2.pl b/challenge-326/perlboy1967/perl/ch-2.pl index 1d542bf4bd..1d542bf4bd 100755 --- a/challenge-326/perlboy1967/perl/ch2.pl +++ b/challenge-326/perlboy1967/perl/ch-2.pl diff --git a/challenge-326/ulrich-rieke/cpp/ch-1.cpp b/challenge-326/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..cfa8ba6374 --- /dev/null +++ b/challenge-326/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,34 @@ +#include <vector>
+#include <string>
+#include <sstream>
+#include <iostream>
+#include <chrono>
+
+std::vector<std::string> split( const std::string & text , char delimiter ) {
+ std::vector<std::string> tokens ;
+ std::string word ;
+ std::istringstream istr { text } ;
+ while ( std::getline( istr , word , delimiter ))
+ tokens.push_back( word ) ;
+ return tokens ;
+}
+
+int number_of_days( std::chrono::sys_days const & first ,
+ std::chrono::sys_days const & second ) {
+ return (second - first).count( ) ;
+}
+
+int main( ) {
+ std::cout << "Enter a valid date in the form YYYY-MM-DD!\n" ;
+ std::string dateline ;
+ std::cin >> dateline ;
+ auto parts { split( dateline , '-' ) } ;
+ std::chrono::year ye( std::stoi( parts[0] ) ) ;
+ std::chrono::month m( std::stoi( parts[1] ) ) ;
+ std::chrono::day d( std::stoi( parts[2] ) ) ;
+ std::chrono::year_month_day given = ye/ m / d ;
+ std::chrono::year_month_day start = ye/ 1 / 1 ;
+ std::cout << (number_of_days( start , given ) + 1 ) << '\n' ;
+ return 0 ;
+}
+
diff --git a/challenge-326/ulrich-rieke/cpp/ch-2.cpp b/challenge-326/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..f7871488fc --- /dev/null +++ b/challenge-326/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,38 @@ +#include <vector>
+#include <string>
+#include <sstream>
+#include <iostream>
+
+std::vector<std::string> split( const std::string & text , char delimiter ) {
+ std::vector<std::string> tokens ;
+ std::string word ;
+ std::istringstream istr { text } ;
+ while ( std::getline( istr , word , delimiter ))
+ tokens.push_back( word ) ;
+ return tokens ;
+}
+
+int main( ) {
+ std::cout << "Enter an even amount of positive integers separated by blanks!\n";
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ auto tokens { split( line , ' ' ) } ;
+ std::vector<int> numbers ;
+ for ( auto s : tokens )
+ numbers.push_back(std::stoi( s ) ) ;
+ std::vector<int> solution ;
+ int len = numbers.size( ) ;
+ int pos = 0 ;
+ while ( pos < len - 1 ) {
+ int howmany = numbers[pos] ;
+ for ( int i = 0 ; i < howmany ; i++ )
+ solution.push_back( numbers[pos + 1] ) ;
+ pos += 2 ;
+ }
+ std::cout << "( " ;
+ for ( int i : solution ) {
+ std::cout << i << ' ' ;
+ }
+ std::cout << ")\n" ;
+ return 0 ;
+}
diff --git a/challenge-326/ulrich-rieke/haskell/ch-1.hs b/challenge-326/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..40b49d3554 --- /dev/null +++ b/challenge-326/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,20 @@ +module Challenge326
+ where
+import Data.Time.Calendar
+import Data.List.Split ( splitOn )
+
+solution :: String -> Integer
+solution input =
+ let [ part1 , part2 , part3 ] = splitOn "-" input
+ year = (read part1 :: Integer )
+ month = read part2
+ day = read part3
+ start = fromGregorian year 1 1
+ in (diffDays ( fromGregorian year month day ) start) + 1
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a date in the form YYYY-MM-DD !"
+ dateline <- getLine
+ print $ solution dateline
+
diff --git a/challenge-326/ulrich-rieke/haskell/ch-2.hs b/challenge-326/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..d563d8ca9c --- /dev/null +++ b/challenge-326/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,13 @@ +module Challenge326_2
+ where
+import Data.List.Split (chunksOf )
+
+solution :: [Int] -> [Int]
+solution list = foldl1 ( ++ ) $ map (\subli -> replicate ( head subli )
+ ( last subli ) ) $ chunksOf 2 list
+
+main :: IO ( )
+main = do
+ putStrLn "Enter an even amount of positive integers separated by blanks!"
+ numberline <- getLine
+ print $ solution $ map read $ words numberline
diff --git a/challenge-326/ulrich-rieke/perl/ch-1.pl b/challenge-326/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..7512dda549 --- /dev/null +++ b/challenge-326/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use Date::Calc qw ( Delta_Days );
+
+say "Enter a date in the form YYYY-MM-DD !" ;
+my $line = <STDIN> ;
+chomp $line ;
+$line =~ s/\-0/\-/g ;
+if ( $line =~ /^(\d{4})\-(\d+)\-(\d+)$/ ) {
+ my ( $year , $month , $day ) = ( $1 , $2 , $3 ) ;
+ my $diff_days = Delta_Days( $year , 1 , 1 , $year , $month , $day) ;
+ say $diff_days + 1 ;
+}
+else {
+ say "Data not in the right format!" ;
+}
diff --git a/challenge-326/ulrich-rieke/perl/ch-2.pl b/challenge-326/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..d46ee43e94 --- /dev/null +++ b/challenge-326/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter an even amount of positive integers separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s/ , $line ) ;
+my $len = scalar( @numbers ) ;
+my @solution ;
+my $pos = 0 ;
+while ( $pos < $len - 1 ) {
+ my $howmany = $numbers[$pos] ;
+ for (0..$howmany - 1) {
+ push( @solution , $numbers[$pos + 1] ) ;
+ }
+ $pos += 2 ;
+}
+say "(" . join( ',' , @solution) . ")" ;
diff --git a/challenge-326/ulrich-rieke/raku/ch-1.raku b/challenge-326/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..659a324bbe --- /dev/null +++ b/challenge-326/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,16 @@ +use v6 ;
+
+say "Enter a valid date in the form YYYY-MM-DD !" ;
+my $line = $*IN.get ;
+my $someDate ;
+$line ~~ s:g/\- 0/\-/ ;
+if ( $line ~~ /^(\d ** 4) '-' (\d+) '-' (\d+)$/ ) {
+ my ( $year , $month , $day ) = ( +$0 , +$1 , +$2 ) ;
+ say ( $year , $month , $day ) ;
+ $someDate = Date.new( $year , $month , $day ) ;
+ my $start = Date.new( $year , 1 , 1 ) ;
+ say ($someDate - $start) + 1 ;
+}
+else {
+ say "Invalid format!" ;
+}
diff --git a/challenge-326/ulrich-rieke/raku/ch-2.raku b/challenge-326/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..6b76f9a851 --- /dev/null +++ b/challenge-326/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,16 @@ +use v6 ;
+
+say "Enter an even amount of positive integers separated by blanks!" ;
+my $line = $*IN.get ;
+my @numbers = $line.words.map( {.Int} ) ;
+my $len = @numbers.elems ;
+my @solution ;
+my $pos = 0 ;
+while ( $pos < $len - 1 ) {
+ my $howmany = @numbers[$pos] ;
+ for (0..$howmany - 1 ) {
+ @solution.push( @numbers[$pos + 1]) ;
+ }
+ $pos += 2 ;
+}
+say "(" ~ @solution.join( ',' ) ~ ")" ;
diff --git a/challenge-326/ulrich-rieke/rust/ch-1.rs b/challenge-326/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..bd9f5ea83a --- /dev/null +++ b/challenge-326/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,14 @@ +use std::io ; +use chrono::{NaiveDate , Datelike} ; + +fn main() { + println!("Enter a day in the format YYYY-MM-DD!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let trimmed = inline.trim( ) ; + let year : i32 = trimmed[0..4].parse::<i32>( ).unwrap( ) ; + let mo : u32 = trimmed[5..7].parse::<u32>( ).unwrap( ) ; + let d : u32 = trimmed[8..10].parse::<u32>( ).unwrap( ) ; + let date = NaiveDate::from_ymd_opt( year , mo , d ).unwrap( ) ; + println!("{}" , Datelike::ordinal0( &date ) + 1) ; +} diff --git a/challenge-326/ulrich-rieke/rust/ch-2.rs b/challenge-326/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..63fc008484 --- /dev/null +++ b/challenge-326/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,21 @@ +use std::io ; + +fn main() { + println!("Enter an even amount of positive integers separated by blanks!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let numbers : Vec<u32> = inline.trim( ).split_whitespace( ).map( |s| + s.parse::<u32>( ).unwrap( )).collect( ) ; + let mut solution : Vec<u32> = Vec::new( ) ; + let len : usize = numbers.len( ) ; + let mut pos : usize = 0 ; + while pos < len - 1 { + let howmany : usize = numbers[pos] as usize ; + let num : u32 = numbers[pos + 1] ; + for _ in 0..howmany { + solution.push( num ) ; + } + pos += 2 ; + } + println!("{:?}" , solution ) ; +} diff --git a/stats/pwc-challenge-325.json b/stats/pwc-challenge-325.json new file mode 100644 index 0000000000..ab6b3109a1 --- /dev/null +++ b/stats/pwc-challenge-325.json @@ -0,0 +1,593 @@ +{ + "chart" : { + "type" : "column" + }, + "drilldown" : { + "series" : [ + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Adam Russell", + "name" : "Adam Russell" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Ali Moradi", + "name" : "Ali Moradi" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Andreas Mahnke", + "name" : "Andreas Mahnke" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Andrew Shitov", + "name" : "Andrew Shitov" + }, + { + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Arne Sommer", + "name" : "Arne Sommer" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Athanasius", + "name" : "Athanasius" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Bob Lied", + "name" : "Bob Lied" + }, + { + "data" : [ + [ + "Blog", + 2 + ] + ], + "id" : "David Ferrone", + "name" : "David Ferrone" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "E. Choroba", + "name" : "E. Choroba" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Feng Chang", + "name" : "Feng Chang" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Jan Krnavek", + "name" : "Jan Krnavek" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Kjetil Skotheim", + "name" : "Kjetil Skotheim" + }, + { + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 10 + ] + ], + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Mark Anderson", + "name" : "Mark Anderson" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Matthias Muth", + "name" : "Matthias Muth" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Niels van Dijke", + "name" : "Niels van Dijke" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Packy Anderson", + "name" : "Packy Anderson" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Peter Meszaros", + "name" : "Peter Meszaros" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Robbie Hatley", + "name" : "Robbie Hatley" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Robert Ransbottom", + "name" : "Robert Ransbottom" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Roger Bell_West", + "name" : "Roger Bell_West" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Simon Green", + "name" : "Simon Green" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Thomas Kohler", + "name" : "Thomas Kohler" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "W. Luis Mochan", + "name" : "W. Luis Mochan" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Walt Mankowski", + "name" : "Walt Mankowski" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Wanderdoc", + "name" : "Wanderdoc" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Yitzchak Scott-Thoennes", + "name" : "Yitzchak Scott-Thoennes" + } + ] + }, + "legend" : { + "enabled" : 0 + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "series" : [ + { + "colorByPoint" : 1, + "data" : [ + { + "drilldown" : "Adam Russell", + "name" : "Adam Russell", + "y" : 4 + }, + { + "drilldown" : "Ali Moradi", + "name" : "Ali Moradi", + "y" : 3 + }, + { + "drilldown" : "Andreas Mahnke", + "name" : "Andreas Mahnke", + "y" : 2 + }, + { + "drilldown" : "And |
