diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-07-02 23:41:30 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-07-02 23:41:30 +0100 |
| commit | cc7c782687a44568308b337c1986ebd0620d5dc3 (patch) | |
| tree | fb5782212e552f6518f982cd781c71763bba2422 | |
| parent | 47ee64ca88a82fdff9a237274bb3ed6b275391b8 (diff) | |
| download | perlweeklychallenge-club-cc7c782687a44568308b337c1986ebd0620d5dc3.tar.gz perlweeklychallenge-club-cc7c782687a44568308b337c1986ebd0620d5dc3.tar.bz2 perlweeklychallenge-club-cc7c782687a44568308b337c1986ebd0620d5dc3.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Ulrich Rieke.
- Added solutions by Andrew Shitov.
- Added solutions by Feng Chang.
- Added solutions by Mark Anderson.
- Added solutions by E. Choroba.
- Added solutions by Simon Proctor.
- Added solutions by David Ferrone.
- Added solutions by Thomas Kohler.
- Added solutions by PokGoPun.
- Added solutions by Peter Campbell Smith.
- Added solutions by Dave Jacoby.
- Added solutions by Ali Moradi.
- Added solutions by Wanderdoc.
- Added solutions by Benjamin Andre.
- Added solutions by Yitzchak Scott-Thoennes.
37 files changed, 1063 insertions, 457 deletions
diff --git a/challenge-328/eric-cheung/python/ch-1.py b/challenge-328/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..df35c89b20 --- /dev/null +++ b/challenge-328/eric-cheung/python/ch-1.py @@ -0,0 +1,26 @@ +
+## strInput = "a?z" ## Example 1
+## strInput = "pe?k" ## Example 2
+strInput = "gra?te" ## Example 3
+
+arrOutput = []
+
+arrReplaceList = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
+
+for nIndx, charLoop in enumerate(strInput):
+ if charLoop != "?":
+ arrOutput.append(charLoop)
+ continue
+
+ ## print (nIndx, charLoop)
+
+ arrExclude = []
+ if nIndx > 0:
+ arrExclude.append(strInput[nIndx - 1])
+
+ if nIndx < len(strInput) - 1:
+ arrExclude.append(strInput[nIndx + 1])
+
+ arrOutput.append([charSubLoop for charSubLoop in arrReplaceList if not charSubLoop in arrExclude][0])
+
+print ("".join(arrOutput))
diff --git a/challenge-328/eric-cheung/python/ch-2.py b/challenge-328/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..346602cc99 --- /dev/null +++ b/challenge-328/eric-cheung/python/ch-2.py @@ -0,0 +1,29 @@ +
+## strInput = "WeEeekly" ## Example 1
+## strInput = "abBAdD" ## Example 2
+strInput = "abc" ## Example 3
+
+bProceed = True
+strTemp = strInput
+
+while bProceed:
+ bFound = False
+ arrTemp = list(strTemp)
+ for nIndx, charLoop in enumerate(arrTemp):
+ if nIndx == 0:
+ continue
+
+ if charLoop.lower() == arrTemp[nIndx - 1].lower() and charLoop != arrTemp[nIndx - 1]:
+ del arrTemp[nIndx]
+ del arrTemp[nIndx - 1]
+ bFound = True
+ break
+
+ strTemp = "".join(arrTemp)
+
+ if bFound:
+ continue
+
+ bProceed = False
+
+print (strTemp)
diff --git a/challenge-328/ulrich-rieke/cpp/ch-1.cpp b/challenge-328/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..e89126afdb --- /dev/null +++ b/challenge-328/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,26 @@ +#include <iostream>
+#include <string>
+#include <vector>
+#include <numeric>
+
+int main( ) {
+ std::cout << "Enter a word with lowercase English letters and one ?!\n" ;
+ std::string word ;
+ std::getline( std::cin , word ) ;
+ std::vector<char> characters( 26 ) ;
+ std::iota( characters.begin( ) , characters.end( ) , 'a' ) ;
+ auto found = word.find( '?' ) ;
+ char left_neighbour = word.substr( 0 , found ).back( ) ;
+ char right_neighbour = word.substr( found + 1 ).front( ) ;
+ std::vector<char> remaining ;
+ for ( auto c : characters ) {
+ if (c != left_neighbour && c != right_neighbour ) {
+ remaining.push_back( c ) ;
+ }
+ }
+ std::string changed { word.substr( 0 , found ) } ;
+ changed.push_back( remaining[0] ) ;
+ changed.append( word.substr( found + 1 ) ) ;
+ std::cout << changed << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-328/ulrich-rieke/cpp/ch-2.cpp b/challenge-328/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..37f52fc15c --- /dev/null +++ b/challenge-328/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,33 @@ +#include <iostream>
+#include <string>
+#include <cstdlib>
+
+int main( ) {
+ std::cout << "Enter a word with English letters only!\n" ;
+ std::string word ;
+ std::getline( std::cin , word ) ;
+ std::string solution ;
+ int len = static_cast<int>(word.length( ) ) ;
+ int pos = 0 ;
+ while ( pos < len ) {
+ solution.push_back( word[pos] ) ;
+ int l = static_cast<int>(solution.length( ) ) ;
+ if ( l > 1 ) {
+ char first = solution[l - 2] ;
+ char second = solution[l - 1] ;
+ if ( std::abs( static_cast<int>( first ) - static_cast<int>(second ) )
+ == 32 ) {
+ solution = solution.substr( 0 , l - 2 ) ;
+ }
+ }
+ pos++ ;
+ }
+ if ( solution.length( ) > 0 ) {
+ std::cout << solution ;
+ }
+ else {
+ std::cout << "\"\"" ;
+ }
+ std::cout << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-328/ulrich-rieke/haskell/ch-1.hs b/challenge-328/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..16cf15368a --- /dev/null +++ b/challenge-328/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,18 @@ +module Challenge328
+ where
+import Data.List ( findIndices , (\\) , (!!) )
+
+change :: String -> String
+change str =
+ let position = head $ findIndices (== '?' ) str
+ left = if position > 0 then position - 1 else 0
+ l = length str
+ right = if position < l - 1 then position + 1 else l - 1
+ remaining = ['a'..'z'] \\ [str !! left , str !! right]
+ in take position str ++ [head remaining] ++ drop ( position + 1 ) str
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a string with lowercase English letters and one ?!"
+ wordline <- getLine
+ print $ change wordline
diff --git a/challenge-328/ulrich-rieke/haskell/ch-2.hs b/challenge-328/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..0b102d9641 --- /dev/null +++ b/challenge-328/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,30 @@ +module Challenge328_2
+ where
+import Data.List.Split( divvy )
+import Data.List ( findIndex , (!!))
+import Data.Char ( ord )
+import Data.Maybe ( isJust , fromJust )
+
+condition :: [(Int , Char)] -> Bool
+condition sublist = abs ( (ord $ snd $ head sublist) - ( ord $ snd $ last
+ sublist )) == 32
+
+changeStr :: String -> String
+changeStr str =
+ let zipped = zip [0 , 1 .. ] str
+ paired = divvy 2 1 zipped
+ result = findIndex condition paired
+ in if isJust result then take (fst $ head $ paired !! (fromJust result)) str ++
+ ( drop ((fst $ last $ paired !! (fromJust result) ) + 1 ) str ) else str
+
+solution :: String -> String
+solution str = fst $ until snd step ( str , False )
+ where
+ step :: (String , Bool) -> (String , Bool)
+ step ( aString , changed ) = ( changeStr aString , changeStr aString == aString)
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a word with English letters only!"
+ aWord <- getLine
+ print $ solution aWord
diff --git a/challenge-328/ulrich-rieke/perl/ch-1.pl b/challenge-328/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..85736e36c7 --- /dev/null +++ b/challenge-328/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter a word with lower case English characters and one ?!" ;
+my $word = <STDIN> ;
+chomp $word ;
+my @characters = ('a'..'z') ;
+my %found ;
+if ( $word =~ /(.)\?(.)/ ) {
+ $found{$1}++ ;
+ $found{$2}++ ;
+}
+my @difference = grep { not exists( $found{$_} ) } @characters ;
+my $replacement = $difference[0] ;
+$word =~ s/\?/$replacement/ ;
+say $word ;
diff --git a/challenge-328/ulrich-rieke/perl/ch-2.pl b/challenge-328/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..23e6577f9f --- /dev/null +++ b/challenge-328/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter a string with English letters!" ;
+my $word = <STDIN> ;
+chomp $word ;
+my $solution ;
+my $len = length( $word ) ;
+my $pos = 0 ;
+while ( $pos < $len ) {
+ $solution .= substr( $word , $pos , 1 ) ;
+ my $l = length( $solution ) ;
+ if ( $l > 1 ) {
+ my $first = substr( $solution , $l - 2 , 1 ) ;
+ my $second = substr( $solution , $l - 1 , 1 ) ;
+ if ( abs( ord( $first ) - ord( $second ) ) == 32 ) {
+ $solution = substr( $solution , 0 , $l - 2 ) ;
+ }
+ }
+ $pos++ ;
+}
+if ( $solution ) {
+ say $solution ;
+}
+else {
+ say "\"\"" ;
+}
diff --git a/challenge-328/ulrich-rieke/raku/ch-1.raku b/challenge-328/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..ac5f7a04e5 --- /dev/null +++ b/challenge-328/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,11 @@ +use v6 ;
+
+say "Enter a word!" ;
+my $word = $*IN.get ;
+my $characters = ('a'..'z').Set ;
+if ( $word ~~ /(.) '?' (.)/ ) {
+ my $remaining = $characters (-) (~$0 , ~$1).Set ;
+ my $replacement = $remaining.keys[0] ;
+ $word ~~ s/'?'/$replacement/ ;
+}
+say $word ;
diff --git a/challenge-328/ulrich-rieke/raku/ch-2.raku b/challenge-328/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..05cb658c75 --- /dev/null +++ b/challenge-328/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,25 @@ +use v6 ;
+
+say "Enter a word with English letters only!" ;
+my $word = $*IN.get ;
+my $solution ;
+my $len = $word.chars ;
+my $pos = 0 ;
+while ( $pos < $len ) {
+ $solution ~= $word.substr( $pos , 1 ) ;
+ my $l = $solution.chars ;
+ if ( $l > 1 ) {
+ my $first = $solution.substr( $l - 2 , 1 ) ;
+ my $second = $solution.substr( $l - 1 , 1 ) ;
+ if (( $first.ord - $second.ord).abs == 32 ) {
+ $solution = $solution.substr( 0 , $l - 2 ) ;
+ }
+ }
+ $pos++ ;
+}
+if ( $solution ) {
+ say $solution ;
+}
+else {
+ say "\"\"" ;
+}
diff --git a/challenge-328/ulrich-rieke/rust/ch-1.rs b/challenge-328/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..703cd2b785 --- /dev/null +++ b/challenge-328/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,39 @@ +use std::io ; +use std::collections::HashSet ; + +fn main() { + println!("Enter a string with lowercase English letters and one ?!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let trimmed = inline.trim( ) ; + let mut characters : HashSet<char> = HashSet::new( ) ; + for c in 'a'..='z' { + characters.insert( c ) ; + } + let len : usize = trimmed.chars( ).count( ) ; + let mut after : String = String::new( ) ; + if let Some( pos ) = trimmed.find( '?' ) { + let mut left_neighbour : char = ' ' ; + let mut right_neighbour : char = ' ' ; + if pos > 0 { + left_neighbour = trimmed.chars( ).nth(pos - 1).unwrap( ) ; + } + if pos < len - 1 { + right_neighbour = trimmed.chars( ).nth( pos + 1 ).unwrap( ) ; + } + let mut already_there : HashSet<char> = HashSet::new( ) ; + already_there.insert( left_neighbour ) ; + already_there.insert( right_neighbour ) ; + let diff : HashSet<&char> = characters.difference( &already_there ).collect( ) ; + if diff.len( ) > 0 { + let mut repl : String = String::new( ) ; + for x in diff.iter( ) { + repl.push(**x) ; + break ; + } + let replacement = repl.as_str( ) ; + after = trimmed.replace( "?" , replacement ) ; + } + } + println!("{:?}" , after ) ; +} diff --git a/challenge-328/ulrich-rieke/rust/ch-2.rs b/challenge-328/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..350bcdf5fe --- /dev/null +++ b/challenge-328/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,31 @@ +use std::io ; + +fn main() { + println!("Enter a string with English letters only!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let mut entered : &str = inline.trim( ) ; + let mut trimmed : String = entered.into( ) ; + let mut len : usize = entered.chars( ).count( ) ; + let mut pos : usize = 0 ; + while pos < len - 1 { + let first_char : char = entered.chars( ).nth( pos ).unwrap( ) ; + let second_char : char = entered.chars( ).nth( pos + 1 ).unwrap( ) ; + if (first_char.to_ascii_lowercase( ) == second_char || + first_char.to_ascii_uppercase( ) == second_char ) && + first_char != second_char { + trimmed.remove( pos ) ; + trimmed.remove( pos ) ; + entered = trimmed.as_str( ) ; + len = entered.chars( ).count( ) ; + if len == 0 { + break ; + } + pos = 0 ; + } + else { + pos += 1 ; + } + } + println!("{:?}" , trimmed ) ; +} diff --git a/guests.json b/guests.json index cfcdf884fa..f27a00660d 100644 --- a/guests.json +++ b/guests.json @@ -4,6 +4,7 @@ "archargelod" : "Archar Gelod", "ashwin-shenoy" : "Ashwin Shenoy", "aviral-goel" : "Aviral Goel", + "benjamin-andre" : "Benjamin Andre", "chazzka" : "Chazzka", "conor-hoekstra" : "Conor Hoekstra", "daniel-aberger" : "Daniel Aberger", diff --git a/stats/pwc-challenge-327.json b/stats/pwc-challenge-327.json new file mode 100644 index 0000000000..bf9b729696 --- /dev/null +++ b/stats/pwc-challenge-327.json @@ -0,0 +1,607 @@ +{ + "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 + ] + ], + "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" : [ + [ + "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 + ] + ], + "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" : [ + [ + "Blog", + 1 + ] + ], + "id" : "Roger Bell_West", + "name" : "Roger Bell_West" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "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 + ] + ], + "id" : "Ulrich Reining", + "name" : "Ulrich Reining" + }, + { + "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", + 1 + ] + ], + "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 + }, + { + "dri |
