diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-09-23 00:04:07 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-09-23 00:04:07 +0100 |
| commit | 30b12921af1cb617911d9afbcb55b3d947bd2f8a (patch) | |
| tree | 8f0306f3bcc951a5bf2941dc6c1979dd1de1ac06 | |
| parent | 51307d1b8af8ceaeba0a859c6a17e6ace6f68032 (diff) | |
| download | perlweeklychallenge-club-30b12921af1cb617911d9afbcb55b3d947bd2f8a.tar.gz perlweeklychallenge-club-30b12921af1cb617911d9afbcb55b3d947bd2f8a.tar.bz2 perlweeklychallenge-club-30b12921af1cb617911d9afbcb55b3d947bd2f8a.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Ulrich Rieke.
- Added solutions by Andrew Shitov.
- Added solutions by Mark Anderson.
- Added solutions by Feng Chang.
- Added solutions by Niels van Dijke.
- Added solutions by PokGoPun.
- Added solutions by E. Choroba.
- Added solutions by Andreas Mahnke.
- Added solutions by Simon Proctor.
- Added solutions by Lubos Kolouch.
- Added solutions by Richard Park.
- Added solutions by Conor Hoekstra.
- Added solutions by David Ferrone.
- Added solutions by Bob Lied.
- Added solutions by Peter Campbell Smith.
- Added solutions by W. Luis Mochan.
- Added solutions by Benjamin Andre.
- Added solutions by Wanderdoc.
- Added solutions by Thomas Kohler.
42 files changed, 929 insertions, 393 deletions
diff --git a/challenge-339/conor-hoekstra/ch-1.bqn b/challenge-339/conor-hoekstra/bqn/ch-1.bqn index a54b321e16..a54b321e16 100644 --- a/challenge-339/conor-hoekstra/ch-1.bqn +++ b/challenge-339/conor-hoekstra/bqn/ch-1.bqn diff --git a/challenge-339/conor-hoekstra/ch-2.bqn b/challenge-339/conor-hoekstra/bqn/ch-2.bqn index 367b144c92..367b144c92 100644 --- a/challenge-339/conor-hoekstra/ch-2.bqn +++ b/challenge-339/conor-hoekstra/bqn/ch-2.bqn diff --git a/challenge-340/conor-hoekstra/ch-1.bqn b/challenge-340/conor-hoekstra/bqn/ch-1.bqn index c43f038cd2..c43f038cd2 100644 --- a/challenge-340/conor-hoekstra/ch-1.bqn +++ b/challenge-340/conor-hoekstra/bqn/ch-1.bqn diff --git a/challenge-340/conor-hoekstra/ch-2.bqn b/challenge-340/conor-hoekstra/bqn/ch-2.bqn index 904f0729c4..904f0729c4 100644 --- a/challenge-340/conor-hoekstra/ch-2.bqn +++ b/challenge-340/conor-hoekstra/bqn/ch-2.bqn diff --git a/challenge-340/eric-cheung/python/ch-1.py b/challenge-340/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..d1bf6f5b4a --- /dev/null +++ b/challenge-340/eric-cheung/python/ch-1.py @@ -0,0 +1,19 @@ +
+## strInput = "abbaca" ## Example 1
+## strInput = "azxxzy" ## Example 2
+## strInput = "aaaaaaaa" ## Example 3
+## strInput = "aabccba" ## Example 4
+strInput = "abcddcba" ## Example 5
+
+arrOutput = list(strInput)
+
+nIndx = 1
+while nIndx < len(arrOutput):
+ if arrOutput[nIndx] == arrOutput[nIndx - 1]:
+ arrOutput.pop(nIndx)
+ arrOutput.pop(nIndx - 1)
+ nIndx = 1
+ continue
+ nIndx = nIndx + 1
+
+print ("".join(arrOutput))
diff --git a/challenge-340/eric-cheung/python/ch-2.py b/challenge-340/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..c5de473983 --- /dev/null +++ b/challenge-340/eric-cheung/python/ch-2.py @@ -0,0 +1,12 @@ +
+## strInput = "The cat has 3 kittens 7 toys 10 beds" ## Example 1
+## strInput = "Alice bought 5 apples 2 oranges 9 bananas" ## Example 2
+## strInput = "I ran 1 mile 2 days 3 weeks 4 months" ## Example 3
+## strInput = "Bob has 10 cars 10 bikes" ## Example 4
+strInput = "Zero is 0 one is 1 two is 2" ## Example 5
+
+arrNum = [int(strLoop) for strLoop in strInput.split(" ") if strLoop.isnumeric()]
+
+bIsStrictIncrease = all([arrNum[nIndx] > arrNum[nIndx - 1] for nIndx in range(1, len(arrNum))])
+
+print (bIsStrictIncrease)
diff --git a/challenge-340/perlboy1967/perl/ch1.pl b/challenge-340/perlboy1967/perl/ch-1.pl index 144c14472c..144c14472c 100755 --- a/challenge-340/perlboy1967/perl/ch1.pl +++ b/challenge-340/perlboy1967/perl/ch-1.pl diff --git a/challenge-340/perlboy1967/perl/ch2.pl b/challenge-340/perlboy1967/perl/ch-2.pl index 77910075ab..77910075ab 100755 --- a/challenge-340/perlboy1967/perl/ch2.pl +++ b/challenge-340/perlboy1967/perl/ch-2.pl diff --git a/challenge-340/ulrich-rieke/cpp/ch-1.cpp b/challenge-340/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..74ab748d40 --- /dev/null +++ b/challenge-340/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,18 @@ +#include <string>
+#include <regex>
+#include <iterator>
+#include <iostream>
+using namespace std::string_literals ;
+
+int main( ) {
+ std::cout << "Enter a string!\n" ;
+ std::string line ;
+ std::cin >> line ;
+ std::regex re( "(.)\\1" ) ;
+ while ( std::regex_search( line , re ) ) {
+ auto result = std::regex_replace( line, re , ""s ) ;
+ line = result ;
+ }
+ std::cout << line << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-340/ulrich-rieke/cpp/ch-2.cpp b/challenge-340/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..25642587d2 --- /dev/null +++ b/challenge-340/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,34 @@ +#include <string>
+#include <iostream>
+#include <sstream>
+#include <algorithm>
+#include <regex>
+#include <vector>
+
+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 with English letters and numbers only!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ auto tokens { split( line , ' ' ) } ;
+ const std::regex re( "^[1-9][0-9]*$" ) ;
+ std::vector<int> numbers , differences ;
+ for ( auto it = tokens.begin( ) ; it != tokens.end( ) ; ++it ) {
+ if ( std::regex_match( *it , re ))
+ numbers.push_back( std::stoi( *it ) ) ;
+ }
+ for ( int i = 1 ; i < numbers.size( ) ; i++ ) {
+ differences.push_back( numbers[i] - numbers[ i - 1] ) ;
+ }
+ std::cout << std::boolalpha << std::all_of( differences.begin( ) , differences.end( ),
+ [](const int a){ return a > 0 ; }) << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-340/ulrich-rieke/haskell/ch-1.hs b/challenge-340/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..aab8c19db0 --- /dev/null +++ b/challenge-340/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,23 @@ +module Challenge340
+ where
+import Data.List.Split ( divvy )
+import Data.List ( group )
+
+noDoubles :: String -> Bool
+noDoubles = all (\subli -> head subli /= last subli ) . divvy 2 1
+
+excludeDouble :: String -> String
+excludeDouble s =
+ let grouped = group s
+ filtered = filter ((== 1) . length ) grouped
+ in if null filtered then "" else foldl1 (++) $ filter ((== 1) . length) grouped
+
+solution :: String -> String
+solution s = until noDoubles excludeDouble s
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a string!"
+ word <- getLine
+ print $ solution word
+
diff --git a/challenge-340/ulrich-rieke/haskell/ch-2.hs b/challenge-340/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..57b0b2b09b --- /dev/null +++ b/challenge-340/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,17 @@ +module Challenge340_2
+ where
+import Data.Char ( isDigit )
+import Data.List.Split( divvy )
+
+isValidNumber :: String -> Bool
+isValidNumber s = head s /= '0' && all isDigit s
+
+solution :: [String] -> Bool
+solution allWords = all (\subli -> (last subli - head subli) > 0 ) $ divvy 2 1 $
+ map read $ filter isValidNumber allWords
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a string with non-digit letters and numbers only!"
+ line <- getLine
+ print $ solution $ words line
diff --git a/challenge-340/ulrich-rieke/perl/ch-1.pl b/challenge-340/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..01f066184b --- /dev/null +++ b/challenge-340/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter a word!" ;
+my $word = <STDIN> ;
+chomp $word ;
+while ( $word =~ /((.)\2)/cg ) {
+ $word =~ s/$1// ;
+}
+say $word ;
diff --git a/challenge-340/ulrich-rieke/perl/ch-2.pl b/challenge-340/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..0ccf27419f --- /dev/null +++ b/challenge-340/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( all ) ;
+
+say "Enter a string with non-digit English letters and numbers only!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @words = split( /\s+/ , $line ) ;
+my @numbers = grep { $_ =~ /^[1-9][0-9]*$/ } @words ;
+my @differences ;
+for my $pos ( 1..scalar( @numbers ) - 1 ) {
+ push( @differences , $numbers[$pos] - $numbers[$pos - 1] ) ;
+}
+if ( all { $_ > 0 } @differences ) {
+ say "true" ;
+}
+else {
+ say "false" ;
+}
diff --git a/challenge-340/ulrich-rieke/raku/ch-1.raku b/challenge-340/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..95b08997e2 --- /dev/null +++ b/challenge-340/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,11 @@ +use v6 ;
+
+say "Enter a word!" ;
+my $word = $*IN.get ;
+while ( $word ~~ /(.)$0/ ) {
+ my $pos = $word.index( ~$0 ) ;
+ my @letters = $word.comb ;
+ @letters.splice( $pos , 2 , () ) ;
+ $word = @letters.join ;
+}
+say $word ;
diff --git a/challenge-340/ulrich-rieke/raku/ch-2.raku b/challenge-340/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..f829c6d34c --- /dev/null +++ b/challenge-340/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,17 @@ +use v6 ;
+
+say "Enter a string with non-digit English characters and digits without leading 0!" ;
+my $line = $*IN.get ;
+my @words = $line.words ;
+my @numbers ;
+for @words -> $w {
+ if ( $w ~~ /^<[1..9]><[0..9]>*$/ ) {
+ @numbers.push( $w.Int ) ;
+ }
+}
+say @numbers ;
+my @differences ;
+for (1..@numbers.elems - 1) -> $pos {
+ @differences.push( @numbers[$pos] - @numbers[$pos - 1] ) ;
+}
+say (@differences.elems == @differences.grep( {$_ > 0} ).elems);
diff --git a/challenge-340/ulrich-rieke/rust/ch-1.rs b/challenge-340/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..a742f26885 --- /dev/null +++ b/challenge-340/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,22 @@ +use std::io ; +use fancy_regex::Regex ; + +fn main() { + println!("Enter a word!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let mut word : &str = inline.trim( ) ; + let re = Regex::new(r"(.)\1").unwrap( ) ; + let mut result = re.is_match( word ).unwrap( ) ; + let empty : String = "".to_string( ) ; + let mut current : String ; + while result { + let fields : Vec<&str> = re.split( word ).map( |x| x.unwrap( ) ).collect( ) ; + let value : String = fields.iter( ).fold( empty.clone( ) , |acc , w| + acc.to_owned( ) + w ) ; + current = value.clone( ) ; + word = current.as_str( ) ; + result = re.is_match( word ).unwrap( ) ; + } + println!("{}" , word ) ; +} diff --git a/challenge-340/ulrich-rieke/rust/ch-2.rs b/challenge-340/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..e359b8a394 --- /dev/null +++ b/challenge-340/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,18 @@ +use std::io ; +use regex::Regex ; + +fn main() { + println!("Enter a sentence with words consisting of lowercase English"); + println!("or of digits with no leading zeroes only!") ; + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let words : Vec<&str> = inline.trim( ).split_whitespace( ).collect( ) ; + let num = Regex::new( r"^[1-9][0-9]*$").unwrap( ) ; + let numbers : Vec<u32> = words.into_iter( ).filter( |w| num.is_match( w ) ). + map( |w| w.parse::<u32>( ).unwrap( )).collect( ) ; + let mut differences : Vec<u32> = Vec::new( ) ; + for d in 1..numbers.len( ) { + differences.push( numbers[d] - numbers[d - 1] ) ; + } + println!("{}" , differences.into_iter( ).all( |d| d > 0 ) ) ; +} diff --git a/stats/pwc-challenge-339.json b/stats/pwc-challenge-339.json new file mode 100644 index 0000000000..ba8f3b05ed --- /dev/null +++ b/stats/pwc-challenge-339.json @@ -0,0 +1,536 @@ +{ + "chart" : { + "type" : "column" + }, + "drilldown" : { + "series" : [ + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Ali Moradi", + "name" : "Ali Moradi" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Andreas Mahnke", + "name" : "Andreas Mahnke" + }, + { + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Arne Sommer", + "name" : "Arne Sommer" + }, + { + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ] + ], + "id" : "Athanasius", + "name" : "Athanasius" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Bob Lied", + "name" : "Bob Lied" + }, + { + "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", + 1 + ] + ], + "id" : "Jan Krnavek", + "name" : "Jan Krnavek" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Lubos Kolouch", + "name" : "Lubos Kolouch" + }, + { + "data" : [ + [ + "Perl", + 1 + ] + ], + "id" : "Mariano Spadaccini", + "name" : "Mariano Spadaccini" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Mark Anderson", + "name" : "Mark Anderson" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Matthew Neleigh", + "name" : "Matthew Neleigh" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Matthias Muth", + "name" : "Matthias Muth" + }, + { + "data" : [ + [ + "Perl", + 1 + ] + ], + "id" : "Mohammad Sajid Anwar", + "name" : "Mohammad Sajid Anwar" + }, + { + "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" : [ + [ + "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" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Simon Proctor", + "name" : "Simon Proctor" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Thomas Kohler", + "name" : "Thomas Kohler" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Torgny Lyon", + "name" : "Torgny Lyon" + }, + { + "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" : "Ali Moradi", + "name" : "Ali Moradi", + "y" : 5 + }, + { + "drilldown" : "Andreas Mahnke", + "name" : "Andreas Mahnke", + "y" : 2 + }, + { + "drilldown" : "Arne Sommer", + "name" : "Arne Sommer", + "y" : 3 + }, + { + "drilldown" : "Athanasius", + "name" : "Athanasius", + "y" : 2 + }, + { + "drilldown" : "Bob Lied", + "name" : "Bob Lied", + "y" : 3 + }, + { + "drilldown" : "David Ferrone", + "name" : "David Ferrone", + "y" : 2 + }, + { + "drilldown" : "E. Choroba", + "name" : "E. Choroba", + "y" : 2 + }, + { + |
