diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-10-29 20:44:59 +0000 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-10-29 20:44:59 +0000 |
| commit | 65c09e5b2b05b300c933f2ff8d5bc1e44981b930 (patch) | |
| tree | df743323d1b7bb4105c6756cdab063e2652c0455 | |
| parent | 21aed055c3ef9f72495bb72d1f4b6b7cb718d186 (diff) | |
| download | perlweeklychallenge-club-65c09e5b2b05b300c933f2ff8d5bc1e44981b930.tar.gz perlweeklychallenge-club-65c09e5b2b05b300c933f2ff8d5bc1e44981b930.tar.bz2 perlweeklychallenge-club-65c09e5b2b05b300c933f2ff8d5bc1e44981b930.zip | |
- Added solutions by Robbie Hatley.
- Added solutions by Packy Anderson.
- Added solutions by Roger Bell_West.
- Added solutions by Ulrich Rieke.
35 files changed, 475 insertions, 75 deletions
diff --git a/challenge-345/ulrich-rieke/cpp/ch-1.cpp b/challenge-345/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..760749850a --- /dev/null +++ b/challenge-345/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,35 @@ +#include <vector>
+#include <sstream>
+#include <string>
+#include <iostream>
+
+std::vector<std::string> split( const std::string & text , const 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 at least 3 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> indices ;
+ for ( int i = 1 ; i < static_cast<int>(numbers.size( )) - 1 ; i++ ) {
+ if ( numbers[i] > numbers[i - 1] && numbers[i] > numbers[i + 1] ) {
+ indices.push_back( i ) ;
+ }
+ }
+ std::cout << "( " ;
+ for ( int i : indices )
+ std::cout << i << ' ' ;
+ std::cout << ")\n" ;
+ return 0 ;
+}
diff --git a/challenge-345/ulrich-rieke/cpp/ch-2.cpp b/challenge-345/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..10ec683d16 --- /dev/null +++ b/challenge-345/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,54 @@ +#include <vector>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <deque>
+
+std::vector<std::string> split( const std::string & text , const 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 or -1 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::deque<int> seen ;
+ std::vector<int> answers ;
+ int x = 0 ;
+ int len = static_cast<int>( numbers.size( ) ) ;
+ int pos = 0 ;
+ while ( pos < len ) {
+ int n = numbers[pos] ;
+ if ( n > 0 ) {
+ seen.push_front( n ) ;
+ x = 0 ;
+ }
+ else {
+ if ( x < static_cast<int>(seen.size( ) ) ) {
+ answers.push_back( seen[x] ) ;
+ }
+ else {
+ answers.push_back( -1 ) ;
+ }
+ if ( pos < len - 1 && numbers[pos + 1] == -1 )
+ x++ ;
+ }
+ pos++ ;
+ }
+ std::cout << "( " ;
+ for ( int i : answers ) {
+ std::cout << i << ' ' ;
+ }
+ std::cout << ")\n" ;
+ return 0 ;
+}
diff --git a/challenge-345/ulrich-rieke/haskell/ch-1.hs b/challenge-345/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..d332e125fe --- /dev/null +++ b/challenge-345/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,13 @@ +module Challenge345
+ where
+import Data.List ( (!!) )
+
+solution :: [Int] -> [Int]
+solution list = filter (\i -> and[ list !! i > list !! ( i - 1) ,
+ list !! i > list !! ( i + 1 )] ) [1..length list - 2]
+
+main :: IO ( )
+main = do
+ putStrLn "Enter at least 3 integers separated by blanks!"
+ numberline <- getLine
+ print $ solution $ map read $ words numberline
diff --git a/challenge-345/ulrich-rieke/haskell/ch-2.hs b/challenge-345/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..88ada3a748 --- /dev/null +++ b/challenge-345/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,42 @@ +module Challenge345_2
+ where
+import Data.List ( (!!) )
+
+--find the indices of all -1 ; then group them and count the elements of
+--every subgroup
+findCountedNegatives :: [Int] -> [(Int , Int)]
+findCountedNegatives list =
+ let zipped = zip list [0, 1 ..]
+ negatives = filter ( (== -1) . fst ) zipped
+ negativeGroups = groupAsc negatives
+ countedGroups = map (\subli -> zip [0 , 1 ..] (map snd subli) )
+ negativeGroups
+ in concat countedGroups
+
+groupAsc :: [(Int,Int)] -> [[(Int , Int)]]
+groupAsc [] = []
+groupAsc (x:xs) = go [x] xs
+ where
+ go current [] = [current]
+ go current@(cLast:_) (y:ys)
+ | snd y == snd (last current) + 1 = go (current ++ [y]) ys
+ | otherwise = current : go [y] ys
+
+--for every -1 find the corresponding number by looking for all positive
+--numbers left of a -1 , reversing them and taking the right integer
+findNumber :: (Int , Int ) -> [Int] -> Int
+findNumber pair list =
+ let positives = filter ( > 0 ) $ take ( snd pair ) list
+ in if ( fst pair ) < length positives then ( reverse positives ) !!
+ (fst pair) else -1
+
+solution :: [Int] -> [Int]
+solution list =
+ let countedNegatives = findCountedNegatives list
+ in map ( flip findNumber list ) countedNegatives
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some positive numbers and -1 separated by blanks!"
+ numberline <- getLine
+ print $ solution $ map read $ words numberline
diff --git a/challenge-345/ulrich-rieke/perl/ch-1.pl b/challenge-345/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..d591e1d50e --- /dev/null +++ b/challenge-345/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter at least 3 integers separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s/ , $line ) ;
+my @indices ;
+for my $pos( 1..scalar( @numbers) - 2 ) {
+ if ( $numbers[$pos] > $numbers[$pos - 1] && $numbers[$pos] > $numbers[$pos + 1] ) {
+ push( @indices , $pos ) ;
+ }
+}
+say '(' . join( ',' , @indices ) . ')' ;
diff --git a/challenge-345/ulrich-rieke/perl/ch-2.pl b/challenge-345/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..224c972bb1 --- /dev/null +++ b/challenge-345/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter some positive integers or -1 separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @seen ;
+my @answer ;
+my $x = 0 ;
+my @numbers = split( /\s/ , $line ) ;
+my $pos = 0 ;
+my $len = scalar( @numbers ) ;
+while ( $pos < $len ) {
+ my $num = $numbers[$pos] ;
+ if ( $num > 0 ) {
+ $x = 0 ;
+ unshift( @seen , $num ) ;
+ }
+ else {
+ if ( $x < scalar( @seen ) ) {
+ push( @answer , $seen[$x] ) ;
+ }
+ else {
+ push( @answer , -1 ) ;
+ }
+ if ( $pos < $len - 1 && $numbers[$pos + 1] == -1 ) {
+ $x++ ;
+ }
+ }
+ $pos++ ;
+}
+say '(' . join( ',' , @answer ) . ')' ;
+
diff --git a/challenge-345/ulrich-rieke/python/ch-1.py b/challenge-345/ulrich-rieke/python/ch-1.py new file mode 100755 index 0000000000..3e5636bce2 --- /dev/null +++ b/challenge-345/ulrich-rieke/python/ch-1.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3
+
+line = input( "Enter at least 3 integers separated by blanks!\n") ;
+numbers = []
+for w in line.split( ' ' ):
+ numbers.append( int( w ) )
+indices = []
+for i in range(1, len(numbers) - 1):
+ if numbers[i] > numbers[i - 1] and numbers[i] > numbers[i + 1]:
+ indices.append( i )
+print( indices )
diff --git a/challenge-345/ulrich-rieke/python/ch-2.py b/challenge-345/ulrich-rieke/python/ch-2.py new file mode 100755 index 0000000000..1e986b257e --- /dev/null +++ b/challenge-345/ulrich-rieke/python/ch-2.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3
+
+line = input( "Enter some integers and -1 separated by blanks!\n" )
+numbers = []
+for w in line.split( ' ' ):
+ numbers.append(int(w))
+seen = []
+ans = []
+x = 0
+length = len( numbers)
+pos = 0
+while pos < length:
+ n = numbers[pos]
+ if n > 0:
+ x = 0
+ seen.insert( 0 , n )
+ else:
+ if x < len(seen):
+ ans.append( seen[x] )
+ else:
+ ans.append( -1 )
+ if pos < length - 1 and numbers[pos + 1] == -1:
+ x += 1
+ pos += 1
+print( ans )
diff --git a/challenge-345/ulrich-rieke/raku/ch-1.raku b/challenge-345/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..fbaaf9c875 --- /dev/null +++ b/challenge-345/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,12 @@ +use v6 ;
+
+say "Enter at least 3 integers!" ;
+my $line = $*IN.get ;
+my @numbers = $line.words.map( {.Int} ) ;
+my @indices ;
+for (1..@numbers.elems - 2) -> $pos {
+ if (@numbers[$pos] > @numbers[$pos - 1] && @numbers[$pos] > @numbers[$pos + 1]) {
+ @indices.push( $pos ) ;
+ }
+}
+say '(' ~ @indices.join( ',' ) ~ ')' ;
diff --git a/challenge-345/ulrich-rieke/raku/ch-2.raku b/challenge-345/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..04de876e86 --- /dev/null +++ b/challenge-345/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,30 @@ +use v6 ;
+
+say "Enter some positive integers and -1 separated by blanks!" ;
+my $line = $*IN.get ;
+my @numbers = $line.words.map( {.Int} ) ;
+my @seen ;
+my @answer ;
+my $x = 0 ;
+my $pos = 0 ;
+my $len = @numbers.elems ;
+while ( $pos < $len ) {
+ my $num = @numbers[$pos] ;
+ if ( $num > 0 ) {
+ $x = 0 ;
+ @seen.unshift( $num ) ;
+ }
+ else {
+ if ( $x < @seen.elems ) {
+ @answer.push( @seen[$x] ) ;
+ }
+ else {
+ @answer.push( -1 ) ;
+ }
+ if ( $pos < $len - 1 && @numbers[$pos + 1] == -1 ) {
+ $x++ ;
+ }
+ }
+ $pos++ ;
+}
+say '(' ~ @answer.join(',') ~ ')' ;
diff --git a/challenge-345/ulrich-rieke/rust/ch-1.rs b/challenge-345/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..1b3b7e8849 --- /dev/null +++ b/challenge-345/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,16 @@ +use std::io ; + +fn main() { + println!("Enter at least 3 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 indices : Vec<usize> = Vec::new( ) ; + for i in 1..numbers.len( ) -1 { + if numbers[i] > numbers[i - 1] && numbers[i] > numbers[i + 1] { + indices.push( i ) ; + } + } + println!("{:?}" , indices ) ; +} diff --git a/challenge-345/ulrich-rieke/rust/ch-2.rs b/challenge-345/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..574df1f901 --- /dev/null +++ b/challenge-345/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,35 @@ +use std::io ; +use std::collections::VecDeque ; + +fn main() { + println!("Enter some integers and -1 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 seen : VecDeque<i32> = VecDeque::new( ) ; + let mut answer : Vec<i32> = Vec::new( ) ; + let mut x : usize = 0 ; + let len : usize = numbers.len( ) ; + let mut pos : usize = 0 ; + while pos < len { + let n : i32 = numbers[pos] ; + if n > 0 { + x = 0 ; + seen.push_front( n ) ; + } + else { + if x < seen.len( ) { + answer.push( *seen.get( x ).unwrap( ) ) ; + } + else { + answer.push( -1 ) ; + } + if pos < len - 1 && numbers[pos + 1] == -1 { + x += 1 ; + } + } + pos += 1 ; + } + println!("{:?}" , answer ) ; +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 69d5d8bbd1..daef59c3da 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -109,6 +109,24 @@ 2 ], [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Packy Anderson", + "name" : "Packy Anderson" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ "Blog", 1 ] @@ -134,6 +152,30 @@ ], [ "Blog", + 1 + ] + ], + "id" : "Robbie Hatley", + "name" : "Robbie Hatley" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Roger Bell_West", + "name" : "Roger Bell_West" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", 2 ] ], @@ -147,6 +189,20 @@ 2 ], [ + "Raku", + 2 + ] + ], + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ "Blog", 1 ] @@ -218,6 +274,11 @@ "y" : 2 }, { + "drilldown" : "Packy Anderson", + "name" : "Packy Anderson", + "y" : 5 + }, + { "drilldown" : "Peter Campbell Smith", "name" : "Peter Campbell Smith", "y" : 3 @@ -228,11 +289,26 @@ "y" : 2 }, { + "drilldown" : "Robbie Hatley", + "name" : "Robbie Hatley", + "y" : 3 + }, + { + "drilldown" : "Roger Bell_West", + "name" : "Roger Bell_West", + "y" : 2 + }, + { "drilldown" : "Thomas Kohler", "name" : "Thomas Kohler", "y" : 4 }, { + "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke", + "y" : 4 + }, + { "drilldown" : "W. Luis Mochan", "name" : "W. Luis Mochan", "y" : 3 @@ -242,7 +318,7 @@ } ], "subtitle" : { - "text" : "[Champions: 13] Last updated at 2025-10-28 23:37:23 GMT" + "text" : "[Champions: 17] Last updated at 2025-10-29 20:44:29 GMT" }, "title" : { "text" : "The Weekly Challenge - 345" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index e87bc6c627..237addc662 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -970,7 +970,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-28 23:37:23 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-29 20:44:29 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index f369545be4..9a052fa960 100644 --- a/stats/pwc-language-breakdown-2020.json +++ b/stats/pwc-language-breakdown-2020.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-28 23:37:23 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-29 20:44:29 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index e1922460dd..0f5a3e738e 100644 --- a/stats/pwc-language-breakdown-2021.json +++ b/stats/pwc-language-breakdown-2021.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-28 23:37:23 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-29 20:44:29 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 0014232e9f..7357806e0f 100644 --- a/stats/pwc-language-breakdown-2022.json +++ b/stats/pwc-language-breakdown-2022.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-28 23:37:23 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-29 20:44:29 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index 5796a65ff3..67199a89c5 100644 --- a/stats/pwc-language-breakdown-2023.json +++ b/stats/pwc-language-breakdown-2023.json @@ -1200,7 +1200,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-28 23:37:23 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-29 20:44:29 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index 08c696a81a..582f605685 100644 --- a/stats/pwc-language-breakdown-2024.json +++ b/stats/pwc-language-breakdown-2024.json @@ -1246,7 +1246,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-28 23:37:23 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-29 20:44:29 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index b7f037c845..f2cbc3eab6 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,15 +8,15 @@ "data" : [ [ "Perl", - 19 + 25 ], [ "Raku", - 7 + 13 ], [ "Blog", - 5 + 7 ] ], "id" : "345", @@ -799,7 +799,7 @@ { "drilldown" : "345", "name" : "345", - "y" : 31 + "y" : 45 }, { "drilldown" : "344", @@ -1016,7 +1016,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-28 23:37:23 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-10-29 20:44:29 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index e2d06b9932..6b76d9e94c 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,15 +10,15 @@ "data" : [ [ "Perl", - 17765 + 17771 ], [ "Raku", - 9851 + 9857 ], [ "Blog", - 6366 + 6368 ] ], "dataLabels" : { @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-10-28 23:37:23 GMT" + "text" : "Last updated at 2025-10-29 20:44:29 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index 6e61dc9323..07f2986888 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -44,7 +44,7 @@ ], [ "Raku", - 601 + 603 ], [ "Blog", @@ -112,11 +112,11 @@ "data" : [ [ "Perl", - 526 + 528 ], [ "Raku", - 534 + 536 ] ], "id" : "Ulrich Rieke", @@ -346,37 +346,37 @@ "data" : [ [ "Perl", - 269 + 194 ], [ "Raku", - 115 + 194 ], [ "Blog", - 100 + 98 ] ], - "id" : "Ali Moradi", - "name" : "Ali Moradi" + "id" : "Packy Anderson", + "name" : "Packy Anderson" }, { "data" : [ [ "Perl", - 192 + 269 ], [ "Raku", - 192 + 115 ], [ "Blog", - 97 + 100 ] ], - "id" : "Packy Anderson", - "name" : "Packy Anderson" + "id" : "Ali Moradi", + "name" : "Ali Moradi" }, { "data" : [ @@ -442,11 +442,11 @@ "data" : [ [ "Perl", - 300 + 302 ], [ "Blog", - 137 + 138 ] ], "id" : "Robbie Hatley", @@ -807,7 +807,7 @@ { "drilldown" : "Roger Bell_West", "name" : "3: |
