diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-05-20 09:21:46 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-05-20 09:21:46 +0100 |
| commit | e51ae043517be5d93aa80deb9e8e67bf599ceecc (patch) | |
| tree | 06052557446a46c6ad651fc53aed6beacea59616 | |
| parent | b04cb8f401f45f3c831886734b823d35f1079e41 (diff) | |
| download | perlweeklychallenge-club-e51ae043517be5d93aa80deb9e8e67bf599ceecc.tar.gz perlweeklychallenge-club-e51ae043517be5d93aa80deb9e8e67bf599ceecc.tar.bz2 perlweeklychallenge-club-e51ae043517be5d93aa80deb9e8e67bf599ceecc.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Ulrich Rieke.
- Added solutions by Andrew Shitov.
- Added solutions by E. Choroba.
- Added solutions by Niels van Dijke.
- Added solutions by Feng Chang.
- Added solutions by Matthias Muth.
- Added solutions by Mark Anderson.
- Added solutions by Luca Ferrari.
- Added solutions by David Ferrone.
- Added solutions by Steven Wilson.
- Added solutions by Conor Hoekstra.
- Added solutions by W. Luis Mochan.
- Added solutions by Yitzchak Scott-Thoennes.
39 files changed, 979 insertions, 459 deletions
diff --git a/challenge-322/eric-cheung/python/ch-1.py b/challenge-322/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..ca4df0cc2d --- /dev/null +++ b/challenge-322/eric-cheung/python/ch-1.py @@ -0,0 +1,28 @@ +
+## Example 1
+## strInput = "ABC-D-E-F"
+## nInput = 3
+
+## Example 2
+## strInput = "A-BC-D-E"
+## nInput = 2
+
+## Example 3
+strInput = "-A-B-CD-E"
+nInput = 4
+
+arrSplit = strInput.split("-")
+
+arrOutput = []
+strTemp = arrSplit[-1]
+
+for strLoop in arrSplit[:-1][::-1]:
+ if len(strTemp) == nInput:
+ arrOutput.insert(0, strTemp)
+ strTemp = strLoop
+ else:
+ strTemp = strLoop + strTemp
+
+arrOutput.insert(0, strTemp)
+
+print ("-".join(arrOutput))
diff --git a/challenge-322/eric-cheung/python/ch-2.py b/challenge-322/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..bc975d09a7 --- /dev/null +++ b/challenge-322/eric-cheung/python/ch-2.py @@ -0,0 +1,12 @@ +
+## arrInts = [55, 22, 44, 33] ## Example 1
+## arrInts = [10, 10, 10] ## Example 2
+arrInts = [5, 1, 1, 4, 3] ## Example 3
+
+arrSet = sorted(set(arrInts))
+
+## print (arrSet)
+
+arrOutput = [arrSet.index(nLoop) + 1 for nLoop in arrInts]
+
+print (arrOutput)
diff --git a/challenge-322/perlboy1967/perl/ch1.pl b/challenge-322/perlboy1967/perl/ch-1.pl index d945105fd2..d945105fd2 100755 --- a/challenge-322/perlboy1967/perl/ch1.pl +++ b/challenge-322/perlboy1967/perl/ch-1.pl diff --git a/challenge-322/perlboy1967/perl/ch2.pl b/challenge-322/perlboy1967/perl/ch-2.pl index 5e46d4cf12..5e46d4cf12 100755 --- a/challenge-322/perlboy1967/perl/ch2.pl +++ b/challenge-322/perlboy1967/perl/ch-2.pl diff --git a/challenge-322/ulrich-rieke/cpp/ch-1.cpp b/challenge-322/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..e751d0f201 --- /dev/null +++ b/challenge-322/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,44 @@ +#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::istringstream istr { text } ;
+ std::string word ;
+ while ( std::getline( istr , word , delimiter ) )
+ tokens.push_back( word ) ;
+ return tokens ;
+}
+
+int main( ) {
+ std::cout << "Enter a string and a positive number!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ auto tokens { split( line , ' ' ) } ;
+ std::string word { tokens[0] } ;
+ auto it = word.find( "-" ) ;
+ while ( it != std::string::npos ) {
+ word.erase( it , 1 ) ;
+ it = word.find( "-" ) ;
+ }
+ int number { std::stoi( tokens[1] ) } ;
+ std::string solution ;
+ int wordlen = static_cast<int>( word.length( ) ) ;
+ int firstlen = wordlen % number ;
+ int pos = 0 ;
+ if ( firstlen != 0 ) {
+ solution = word.substr( 0 , firstlen ) ;
+ solution.push_back( '-' ) ;
+ pos = firstlen ;
+ }
+ while ( pos + number < wordlen ) {
+ solution += word.substr( pos , number ) ;
+ solution.push_back( '-' ) ;
+ pos += number ;
+ }
+ solution += word.substr( pos ) ;
+ std::cout << solution << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-322/ulrich-rieke/cpp/ch-2.cpp b/challenge-322/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..6b921e83b1 --- /dev/null +++ b/challenge-322/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,44 @@ +#include <iostream>
+#include <vector>
+#include <string>
+#include <utility>
+#include <sstream>
+#include <algorithm>
+
+std::vector<std::string> split( const std::string & text , char delimiter ) {
+ std::vector<std::string> tokens ;
+ std::istringstream istr { text } ;
+ std::string word ;
+ while ( std::getline( istr , word , delimiter ) )
+ tokens.push_back( word ) ;
+ return tokens ;
+}
+
+int main( ) {
+ std::cout << "Enter some 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> for_comp { numbers } ;
+ std::sort( for_comp.begin( ) , for_comp.end( ) ) ;
+ auto up_to = std::unique( for_comp.begin( ) , for_comp.end( ) ) ;
+ std::vector<int> solution ;
+ int n = 0 ;
+ std::vector<std::pair<int , int>> pairs ;
+ for ( auto it = for_comp.begin( ) ; it != up_to ; ++it ) {
+ pairs.push_back( std::make_pair( ++n , *it )) ;
+ }
+ for ( int i : numbers ) {
+ int num = std::find_if( pairs.begin( ) , pairs.end( ) , [i]( auto & p ){
+ return p.second == i ;})->first ;
+ solution.push_back( num ) ;
+ }
+ std::cout << "( " ;
+ for ( auto i : solution )
+ std::cout << i << ' ' ;
+ std::cout << ")\n" ;
+ return 0 ;
+}
diff --git a/challenge-322/ulrich-rieke/haskell/ch-1.hs b/challenge-322/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..1c5e8e915e --- /dev/null +++ b/challenge-322/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,20 @@ +module Challenge322
+ where
+import Data.List.Split ( chunksOf )
+import Data.List ( intercalate )
+
+solution :: String -> Int -> String
+solution str num =
+ let noHyphens = filter ( /= '-' ) str
+ firstlen = mod ( length noHyphens ) num
+ allChunks = if firstlen /= 0 then [take firstlen noHyphens] ++
+ chunksOf num ( drop firstlen noHyphens ) else chunksOf num
+ noHyphens
+ in intercalate "-" allChunks
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a string and a positive integer separated by blanks!"
+ line <- getLine
+ let expressions = words line
+ print $ solution ( head expressions ) ( read $ last expressions )
diff --git a/challenge-322/ulrich-rieke/haskell/ch-2.hs b/challenge-322/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..c8a7008f4a --- /dev/null +++ b/challenge-322/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,17 @@ +module Challenge322_2
+ where
+import qualified Data.Set as S
+import Data.List ( sort )
+import Data.Maybe ( fromJust )
+
+solution :: [Int] -> [Int]
+solution list =
+ let uniques = S.toList $ S.fromList $ sort list
+ zipped = zip uniques [1, 2 ..]
+ in map (\n -> fromJust $ lookup n zipped ) list
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some integers separated by blanks!"
+ numberline <- getLine
+ print $ solution $ map read $ words numberline
diff --git a/challenge-322/ulrich-rieke/perl/ch-1.pl b/challenge-322/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..3b281108fd --- /dev/null +++ b/challenge-322/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter a string and a positive integer separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my ( $word , $number ) = split( /\s/ , $line ) ;
+$word =~ s/\-//g ; #remove all '-'
+my $firstlen = length( $word ) % $number ;
+my $solution ; #final resut
+if ( $firstlen != 0 ) { #length of first part
+ my $firstpart = substr( $word , 0 , $firstlen ) ;
+ $solution = $firstpart . "-" ;
+ my $secondpart = substr( $word , $firstlen ) ;
+ while ( $secondpart =~ /(.{$number})/g ) {
+ $solution .= ($1 . "-") ;
+ }
+}
+else {
+ while ( $word =~ /(.{$number})/g ) {
+ $solution .= ($1 . "-") ;
+ }
+}
+$solution =~ s/\-$// ; #remove final '-'
+say $solution ;
diff --git a/challenge-322/ulrich-rieke/perl/ch-2.pl b/challenge-322/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..5e732063ec --- /dev/null +++ b/challenge-322/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( zip ) ;
+
+say "Enter some integers separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s/ , $line ) ;
+my %numhash ;
+map { $numhash{$_}++ } @numbers ;
+my @zipped = zip [1..scalar( keys %numhash)] , [sort { $a <=> $b } keys
+ %numhash ] ;
+my @solution ;
+for my $n ( @numbers ) {
+ push( @solution , map { $_->[0] } grep { $_->[1] == $n } @zipped ) ;
+}
+say '(' . join( ',' , @solution ) . ')' ;
diff --git a/challenge-322/ulrich-rieke/raku/ch-1.raku b/challenge-322/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..c0e90c1e57 --- /dev/null +++ b/challenge-322/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,23 @@ +use v6 ;
+
+say "Enter a string and a positive integer!" ;
+my $line = $*IN.get ;
+my ($word , $numberstring) = $line.words ;
+my $number = $numberstring.Int ;
+$word ~~ s:g/'-'// ;
+my $wordlen = $word.chars ;
+my $firstlen = $wordlen % $number ;
+my $solution ;
+my $pos = 0 ;
+if ( $firstlen != 0 ) {
+ my $firstpart = $word.substr( 0 , $firstlen ) ;
+ $solution = $firstpart ~ "-" ;
+ $pos = $firstlen ;
+}
+while ( $pos + $number < $wordlen ) {
+ $solution ~= $word.substr( $pos , $number ) ;
+ $solution ~= "-" ;
+ $pos += $number ;
+}
+$solution ~= $word.substr( $pos ) ;
+say $solution ;
diff --git a/challenge-322/ulrich-rieke/raku/ch-2.raku b/challenge-322/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..e7f961feb7 --- /dev/null +++ b/challenge-322/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,12 @@ +use v6 ;
+
+say "Enter some integers separated by blanks!" ;
+my $line = $*IN.get ;
+my @numbers = $line.words.map( {.Int} ) ;
+my @unique_numbers = @numbers.sort( {$^a <=> $^b} ).unique ;
+my @pairs = (1..@unique_numbers.elems) Z, @unique_numbers ;
+my @solution ;
+for @numbers -> $n {
+ @solution.push( @pairs.grep( {$_[1] == $n} ).map( {$_[0]} )) ;
+}
+say '(' ~ @solution.join( ',' ) ~ ')' ;
diff --git a/challenge-322/ulrich-rieke/rust/ch-1.rs b/challenge-322/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..99f19d77f7 --- /dev/null +++ b/challenge-322/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,27 @@ +use std::io ; + +fn main() { + println!("Enter a word and a positive integer separated by blanks!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let words : Vec<&str> = inline.trim( ).split_whitespace( ).collect( ) ; + let number : usize = words[1].parse::<usize>( ).unwrap( ) ; + let word : String = words[0].replace("-" , "") ; + let wordlen : usize = word.len( ) ; + let firstlen : usize = wordlen % number ; + let mut solution : String = String::new( ) ; + let mut pos : usize = 0 ; + if firstlen != 0 { + let firstpart : &str = &word[..firstlen] ; + solution = firstpart.into( ) ; + solution.push('-') ; + pos = firstlen ; + } + while pos + number < wordlen { + solution += &word[pos..pos + number] ; + solution.push( '-' ) ; + pos += number ; + } + solution += &word[pos..] ; + println!("{:?}" , solution ) ; +} diff --git a/challenge-322/ulrich-rieke/rust/ch-2.rs b/challenge-322/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..e5c8bf803e --- /dev/null +++ b/challenge-322/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,20 @@ +use std::io ; + +fn main() { + println!("Enter some integers separated by blanks!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let numbers : Vec<i32> = inline.trim( ).split_whitespace( ).map( |s| + s.parse::<i32>( ).unwrap( )).collect( ) ; + let mut my_numbers : Vec<i32> = numbers.clone( ) ; + my_numbers.sort( ) ; + my_numbers.dedup( ) ; + let pairs : Vec<(usize, i32)> = my_numbers.into_iter( ).enumerate( ). + map( |p| (p.0 + 1 , p.1) ).collect( ) ; + let mut solution : Vec<usize> = Vec::new( ) ; + for n in numbers { + pairs.iter( ).filter( |&p| p.1 == n ).for_each( |p| + solution.push( p.0 )) ; + } + println!("{:?}" , solution ) ; +} diff --git a/members.json b/members.json index f9ebec2a99..82a7de5d14 100644 --- a/members.json +++ b/members.json @@ -319,6 +319,7 @@ "yary-h" : "Yary Hluchan", "yet-ebreo" : "Yet Ebreo", "yozen-hernandez" : "Yozen Hernandez", + "yst" : "Yitzchak Scott-Thoennes", "witawayar" : "Mustafa Aydin", "wlmb" : "W. Luis Mochan", "zapwai" : "David Ferrone", diff --git a/stats/pwc-challenge-321.json b/stats/pwc-challenge-321.json new file mode 100644 index 0000000000..f60e2b41f5 --- /dev/null +++ b/stats/pwc-challenge-321.json @@ -0,0 +1,567 @@ +{ + "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" : [ + [ + "Raku", + 2 + ] + ], + "id" : "BarrOff", + "name" : "BarrOff" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Bob Lied", + "name" : "Bob Lied" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Dave Jacoby", + "name" : "Dave Jacoby" + }, + { + "data" : [ + [ + "Perl", + 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" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey" + }, + { + "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" : "Wanderdoc", + "name" : "Wanderdoc" + } + ] + }, + "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 + }, + |
