diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-07-08 17:15:53 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-07-08 17:15:53 +0100 |
| commit | 09ded88c0f22d977cc3ce8163855b48bf0aec03b (patch) | |
| tree | d17b81f62c5153c70b32ac7ad8bd2ef2ab48fd2a | |
| parent | eb91b5ca3d9f162b147ba570df3aec568fe4cadb (diff) | |
| download | perlweeklychallenge-club-09ded88c0f22d977cc3ce8163855b48bf0aec03b.tar.gz perlweeklychallenge-club-09ded88c0f22d977cc3ce8163855b48bf0aec03b.tar.bz2 perlweeklychallenge-club-09ded88c0f22d977cc3ce8163855b48bf0aec03b.zip | |
- Added solutions by Andrew Shitov.
- Added solutions by E. Choroba.
- Added solutions by Mark Anderson.
- Added solutions by Alexander Karelas.
- Added solutions by Simon Proctor.
- Added solutions by Peter Campbell Smith.
- Added solutions by PokGoPun.
- Added solutions by W. Luis Mochan.
- Added solutions by Wanderdoc.
- Added solutions by Peter Meszaros.
- Added solutions by Niels van Dijke.
- Added solutions by Thomas Kohler.
- Added solutions by Benjamin Andre.
- Added solutions by Feng Chang.
- Added solutions by Yitzchak Scott-Thoennes.
- Added solutions by Ali Moradi.
- Added solutions by David Ferrone.
- Added solutions by Kjetil Skotheim.
38 files changed, 1090 insertions, 372 deletions
diff --git a/challenge-329/eric-cheung/python/ch-1.py b/challenge-329/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..1768c4c152 --- /dev/null +++ b/challenge-329/eric-cheung/python/ch-1.py @@ -0,0 +1,10 @@ +
+## strInput = "the1weekly2challenge2" ## Example 1
+## strInput = "go21od1lu5c7k" ## Example 2
+strInput = "4p3e2r1l" ## Example 3
+
+strOutput = "".join([charLoop if charLoop.isnumeric() else " " for charLoop in strInput])
+
+arrOutput = set([int(strNumLoop) for strNumLoop in strOutput.split(" ") if strNumLoop])
+
+print (arrOutput)
diff --git a/challenge-329/eric-cheung/python/ch-2.py b/challenge-329/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..572cf81fcc --- /dev/null +++ b/challenge-329/eric-cheung/python/ch-2.py @@ -0,0 +1,39 @@ +
+def IsStrNice (strFunc):
+ arrFunc = set(list(strFunc))
+ strChar = strFunc[0]
+ return strChar.upper() in arrFunc and strChar.lower() in arrFunc
+
+## strInput = "YaaAho" ## Example 1
+## strInput = "cC" ## Example 2
+strInput = "A" ## Example 3
+
+arrTemp = []
+strTemp = strInput[0]
+
+for charLoop in strInput[1:]:
+ if charLoop.lower() == strTemp[-1].lower():
+ strTemp = strTemp + charLoop
+ else:
+ arrTemp.append(strTemp)
+ strTemp = charLoop
+
+arrTemp.append(strTemp)
+
+nMaxLen = 0
+arrOutput = []
+
+for strLoop in arrTemp:
+ if not IsStrNice(strLoop):
+ continue
+
+ if len(strLoop) < nMaxLen:
+ continue
+
+ if len(strLoop) > nMaxLen:
+ nMaxLen = len(strLoop)
+ arrOutput = [strLoop]
+ else:
+ arrOutput.append(strLoop)
+
+print (", ".join(arrOutput))
diff --git a/challenge-329/perlboy1967/perl/ch1.pl b/challenge-329/perlboy1967/perl/ch-1.pl index 66bd2f300b..66bd2f300b 100755 --- a/challenge-329/perlboy1967/perl/ch1.pl +++ b/challenge-329/perlboy1967/perl/ch-1.pl diff --git a/challenge-329/perlboy1967/perl/ch2.pl b/challenge-329/perlboy1967/perl/ch-2.pl index 6b0c08ea5e..6b0c08ea5e 100755 --- a/challenge-329/perlboy1967/perl/ch2.pl +++ b/challenge-329/perlboy1967/perl/ch-2.pl diff --git a/challenge-329/ulrich-rieke/cpp/ch-1.cpp b/challenge-329/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..6a275089ea --- /dev/null +++ b/challenge-329/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,35 @@ +#include <string>
+#include <vector>
+#include <regex>
+#include <iostream>
+#include <set>
+using namespace std::string_literals ;
+
+int main( ) {
+ std::cout << "Enter a word with lowercase English letters and digits!\n" ;
+ std::string word ;
+ std::cin >> word ;
+ auto rx = std::regex( R"((\d+))"s ) ;
+ std::vector<std::string> numberstrings ;
+ auto end = std::sregex_token_iterator {} ;
+ for ( auto it = std::sregex_token_iterator(std::begin( word ) ,
+ std::end( word ) , rx ) ; it != end ; ++it ) {
+ numberstrings.push_back( *it ) ;
+ }
+ std::vector<int> numbers ;
+ for ( auto s : numberstrings )
+ numbers.push_back( std::stoi( s ) ) ;
+ std::set<int> uniques { numbers.begin( ) , numbers.end( ) } ;
+ std::vector<int> solution ;
+ for ( int n : numbers ) {
+ if ( uniques.contains( n ) ) {
+ solution.push_back( n ) ;
+ uniques.erase( uniques.find( n ) ) ;
+ }
+ }
+ for ( int n : solution ) {
+ std::cout << n << ' ' ;
+ }
+ std::cout << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-329/ulrich-rieke/cpp/ch-2.cpp b/challenge-329/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..f28db068af --- /dev/null +++ b/challenge-329/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,47 @@ +#include <iostream>
+#include <string>
+#include <vector>
+#include <algorithm>
+#include <cctype>
+
+bool isNice(const std::string & word ) {
+ auto condition = [word]( const char letter ) {
+ if ( std::isupper( static_cast<int>( letter ) ) ) {
+ return word.find( std::tolower( static_cast<int>(letter) )) !=
+ std::string::npos ;
+ }
+ else {
+ return word.find( std::toupper( static_cast<int>(letter))) !=
+ std::string::npos ;
+ }
+ } ;
+ return std::all_of( word.begin( ) , word.end( ) , condition ) ;
+}
+
+int main( ) {
+ std::cout << "Enter a word with uppercase and lowercase English letters only!\n" ;
+ std::string word ;
+ std::cin >> word ;
+ std::vector<std::string> substrings ;
+ int len = static_cast<int>(word.length( )) ;
+ for ( int start = 0 ; start < len - 1 ; start++ ) {
+ for ( int end = start + 1 ; end < len ; end++ ) {
+ substrings.push_back( word.substr( start , end - start + 1 ) ) ;
+ }
+ }
+ std::vector<std::string> selected ;
+ for ( auto s : substrings ) {
+ if ( isNice( s ) )
+ selected.push_back( s ) ;
+ }
+ if ( selected.size( ) > 0 ) {
+ std::sort( selected.begin( ) , selected.end( ) , []( const auto & a , const
+ auto &b ) { return a.length( ) > b.length( ) ; } ) ;
+ std::cout << selected[0] << '\n' ;
+ }
+ else {
+ std::cout << "\"\"" << '\n' ;
+
+ }
+ return 0 ;
+}
diff --git a/challenge-329/ulrich-rieke/haskell/ch-1.hs b/challenge-329/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..49a23165fd --- /dev/null +++ b/challenge-329/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,17 @@ +module Challenge329
+ where
+import Data.Char ( isLetter , isDigit )
+import Data.List ( nub )
+
+solution :: String -> [Int]
+solution str =
+ let replaced = map (\l -> if isLetter l then ' ' else l ) str
+ numberstrings = words replaced
+ numbers = map read numberstrings
+ in nub numbers
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a string with lowercase English letters and digits!"
+ word <- getLine
+ print $ solution word
diff --git a/challenge-329/ulrich-rieke/haskell/ch-2.hs b/challenge-329/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..e3396a6392 --- /dev/null +++ b/challenge-329/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,33 @@ +module Challenge329_2
+ where
+import Data.Char
+import Data.List ( sortOn )
+
+condition :: String -> Bool
+condition str = all (\letter -> any(\l -> abs ( ord l - ord letter ) == 32 ) str ) str
+
+substr :: String -> Int -> Int -> String
+substr str from to = take ( to - from + 1 ) $ drop from str
+
+findSubstrings :: String -> [String]
+findSubstrings str = [substr str from to | from <- [0..l - 2] , to <- [from + 1 ..
+ l - 1]]
+ where
+ l :: Int
+ l = length str
+
+solution :: String -> String
+solution str = if null sorted then "" else last sorted
+ where
+ substrings :: [String]
+ substrings = findSubstrings str
+ selected :: [String]
+ selected = filter condition substrings
+ sorted :: [String]
+ sorted = if null selected then [] else sortOn length selected
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a word with uppercase and lowercase English letters!"
+ word <- getLine
+ print $ solution word
diff --git a/challenge-329/ulrich-rieke/perl/ch-1.pl b/challenge-329/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..515241e5d7 --- /dev/null +++ b/challenge-329/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter a string with lowercase English letters and digits only!" ;
+my $word = <STDIN> ;
+chomp $word ;
+my %found ;
+while ( $word =~ /(\d+)/cg ) {
+ $found{$1} = index( $word , $1 ) ;
+}
+my @sorted = sort { $found{$a} <=> $found{$b} } keys %found ;
+say join( ',' , @sorted ) ;
diff --git a/challenge-329/ulrich-rieke/perl/ch-2.pl b/challenge-329/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..0e3af65136 --- /dev/null +++ b/challenge-329/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( any all ) ;
+
+sub isNice {
+ my $word = shift ;
+ my @letters = split( // , $word ) ;
+ for my $letter( @letters ) {
+ if ( $letter =~ /[A-Z]/ ) {
+ if (not ( any{ $_ eq lc( $letter ) } @letters )) {
+ return 0 ;
+ }
+ }
+ if ( $letter =~ /[a-z]/ ) {
+ if ( not (any { $_ eq uc( $letter ) } @letters )) {
+ return 0 ;
+ }
+ }
+ }
+ return 1 ;
+}
+
+say "Enter a word consisting of uppercase and lowercase English letters!" ;
+my $word = <STDIN> ;
+chomp $word ;
+my $len = length $word ;
+my @substrings ;
+for my $start( 0..$len - 2 ) {
+ for my $end( $start + 1 .. $len - 1 ) {
+ my $subst = substr( $word , $start , $end - $start + 1 ) ;
+ push( @substrings , $subst ) ;
+ }
+}
+my @selected = grep { isNice( $_ ) } @substrings ;
+if ( @selected ) {
+ my @sorted = sort { length( $b ) <=> length( $a ) } @selected ;
+ say $sorted[0] ;
+}
+else {
+ say "\"\"" ;
+}
diff --git a/challenge-329/ulrich-rieke/raku/ch-1.raku b/challenge-329/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..75c0410c25 --- /dev/null +++ b/challenge-329/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,16 @@ +use v6 ;
+
+say "Enter a string consisting of lowercase English letters and digits only!" ;
+my $word = $*IN.get ;
+my $substitute = $word ;
+$substitute ~~ s:g/\D/ / ;
+my @numbers = $substitute.words ;
+my $uniques = @numbers.Set ;
+my @solution ;
+for @numbers -> $n {
+ if ( $n (elem) $uniques ) {
+ $uniques = $uniques (-) ($n).Set ;
+ @solution.push( $n ) ;
+ }
+}
+say @solution.join( ',' ) ;
diff --git a/challenge-329/ulrich-rieke/raku/ch-2.raku b/challenge-329/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..28d2669a78 --- /dev/null +++ b/challenge-329/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,37 @@ +use v6 ;
+
+sub isNice( $substring ) {
+ my @letters = $substring.comb ;
+ for @letters -> $l {
+ if ( $l ~~ /<[A..Z]>/ ) {
+ if ( not so $l.lc eq @letters.any ) {
+ return False ;
+ }
+ }
+ if ( $l ~~ /<[a..z]>/ ) {
+ if ( not so $l.uc eq @letters.any ) {
+ return False ;
+ }
+ }
+ }
+ return True ;
+}
+
+say "Enter a string containing only lowercase and uppercase English letters!" ;
+my $word = $*IN.get ;
+my @substrings ;
+my $len = $word.chars ;
+for (0..$len - 2) -> $start {
+ for ($start + 1 .. $len - 1 ) -> $end {
+ my $subst = $word.substr( $start , $end - $start + 1) ;
+ @substrings.push( $subst ) ;
+ }
+}
+my @selected = @substrings.grep( {isNice( $_) } ) ;
+if ( @selected ) {
+ my @sorted = @selected.sort( {$^b.chars <=> $^a.chars} ) ;
+ say @sorted[0] ;
+}
+else {
+ say "\"\"" ;
+}
diff --git a/challenge-329/ulrich-rieke/rust/ch-1.rs b/challenge-329/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..4c66b78663 --- /dev/null +++ b/challenge-329/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,37 @@ +use std::io ; +use std::collections::HashSet ; + +fn main() { + println!("Enter a word consisting of lowercase letters and digits only!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let after : String = inline.trim( ).replace( |c: char| c.is_alphabetic( ) , " " ); + let remaining : Vec<&str> = after.as_str( ).split(' ').collect( ) ; + let numbers : Vec<i32> = remaining.into_iter( ).filter( |&s| { + s.chars( ).count( ) > 0 && s.chars( ).all( |c| c.is_digit( 10 )) + } ).map( |s| { + let mut sum : i32 = 0 ; + let mut pos : i32 = 1 ; + let mut iter = s.chars( ).rev( ) ; + while let Some( n ) = iter.next( ) { + let oldpos : i32 = pos ; + pos *= n.to_digit( 10 ).unwrap( ) as i32 ; + sum += pos ; + pos = oldpos ; + pos *= 10 ; + } + sum + } ).collect( ) ; + let mut uniques : HashSet<i32> = HashSet::new( ) ; + for n in &numbers { + uniques.insert( *n ) ; + } + let mut solution : Vec<i32> = Vec::new( ) ; + for n in &numbers { + if uniques.remove( &*n ) { + solution.push( *n ) ; + } + } + println!("{:?}" , solution ) ; +} + diff --git a/challenge-329/ulrich-rieke/rust/ch-2.rs b/challenge-329/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..61ed3da5f6 --- /dev/null +++ b/challenge-329/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,40 @@ +use std::io ; + +fn is_nice( substring : &str ) -> bool { + if substring.chars().count( ) == 1 { + return false ; + } + substring.chars( ).all( |c| { + if c.is_ascii_lowercase( ) { + substring.contains( c.to_ascii_uppercase( ) ) + } + else { + substring.contains( c.to_ascii_lowercase( ) ) + } } ) +} + +fn main() { + println!("Enter a word consisting of uppercase and lowercase letters!") ; + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let mut substrings : Vec<&str> = Vec::new( ) ; + let len : usize = inline.len( ) ; + for i in 0..len - 1 { + for j in i + 1..len { + let substr : &str = &inline[i..j] ; + substrings.push( substr ) ; + } + } + let mut selected : Vec<&str> = substrings.into_iter( ).filter( |&s| + is_nice( s ) ).collect( ) ; + let sel_len : usize = selected.len( ) ; + if sel_len > 0 { + let str_cmp = |a: &str , b: &str| a.chars( ).count( ).cmp( &b.chars( ). + count( ) ) ; + selected.sort_by( |arg0: &&str , arg1: &&str| str_cmp(arg0 , arg1 )) ; + println!("{:?}" , selected[sel_len - 1] ) ; + } + else { + println!("\"\"") ; + } +} diff --git a/stats/pwc-challenge-328.json b/stats/pwc-challenge-328.json new file mode 100644 index 0000000000..511c42c2f6 --- /dev/null +++ b/stats/pwc-challenge-328.json @@ -0,0 +1,566 @@ +{ + "chart" : { + "type" : "column" + }, + "drilldown" : { + "series" : [ + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "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" : [ + [ + "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" : [ + [ + "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", + 4 + ] + ], + "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" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Robert Ransbottom", + "name" : "Robert Ransbottom" + }, + { + "data" : [ + [ + "Blog", + 1 + ] + ], + "id" : "Roger Bell_West", + "name" : "Roger Bell_West" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Simon Green", + "name" : "Simon Green" + }, + { + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Simon Proctor", + "name" : "Simon Proctor" + }, + { + "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" + }, + { + |
