diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-08-05 11:55:34 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-08-05 11:55:34 +0100 |
| commit | 153f22e7dc6b1860d8561da89efeeefdfa83eab9 (patch) | |
| tree | 01b2386dbff82575e1de7ec3c1a208295b046fd1 | |
| parent | 4869914836ceba6b2a3f0b2bd762cc5764d46dfb (diff) | |
| download | perlweeklychallenge-club-153f22e7dc6b1860d8561da89efeeefdfa83eab9.tar.gz perlweeklychallenge-club-153f22e7dc6b1860d8561da89efeeefdfa83eab9.tar.bz2 perlweeklychallenge-club-153f22e7dc6b1860d8561da89efeeefdfa83eab9.zip | |
- Added solutions by Lukas Mai.
- Added solutions by E. Choroba.
38 files changed, 1069 insertions, 440 deletions
diff --git a/challenge-333/conor-hoekstra/ch-1.bqn b/challenge-333/conor-hoekstra/bqn/ch-1.bqn index 95dfaa217b..95dfaa217b 100644 --- a/challenge-333/conor-hoekstra/ch-1.bqn +++ b/challenge-333/conor-hoekstra/bqn/ch-1.bqn diff --git a/challenge-333/conor-hoekstra/ch-2.bqn b/challenge-333/conor-hoekstra/bqn/ch-2.bqn index 9e1c5a24bf..9e1c5a24bf 100644 --- a/challenge-333/conor-hoekstra/ch-2.bqn +++ b/challenge-333/conor-hoekstra/bqn/ch-2.bqn diff --git a/challenge-333/eric-cheung/python/ch-1.py b/challenge-333/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..59ee932762 --- /dev/null +++ b/challenge-333/eric-cheung/python/ch-1.py @@ -0,0 +1,26 @@ +
+import numpy as np
+
+def GetSlope (arrPt_1, arrPt_2):
+ dX1, dY1 = arrPt_1
+ dX2, dY2 = arrPt_2
+
+ if dX1 == dX2:
+ return np.nan
+
+ return (dY2 - dY1) / (dX2 - dX1)
+
+## arrList = [[2, 1], [2, 3], [2, 5]] ## Example 1
+## arrList = [[1, 4], [3, 4], [10, 4]] ## Example 2
+## arrList = [[0, 0], [1, 1], [2, 3]] ## Example 3
+## arrList = [[1, 1], [1, 1], [1, 1]] ## Example 4
+arrList = [[1000000, 1000000], [2000000, 2000000], [3000000, 3000000]] ## Example 5
+
+arrX = [arrLoop[0] for arrLoop in arrList]
+arrY = [arrLoop[1] for arrLoop in arrList]
+
+if len(set(arrX)) == 1 or len(set(arrY)) == 1:
+ print (True)
+else:
+ arrSlope = [GetSlope(arrList[nIndx - 1], arrList[nIndx]) for nIndx in range(1, len(arrList))]
+ print (len(set(arrSlope)) == 1)
diff --git a/challenge-333/eric-cheung/python/ch-2.py b/challenge-333/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..7e96b1df40 --- /dev/null +++ b/challenge-333/eric-cheung/python/ch-2.py @@ -0,0 +1,17 @@ +
+## arrInt = [1, 0, 2, 3, 0, 4, 5, 0] ## Example 1
+## arrInt = [1, 2, 3] ## Example 2
+## arrInt = [1, 2, 3, 0] ## Example 3
+## arrInt = [0, 0, 1, 2] ## Example 4
+arrInt = [1, 2, 0, 3, 4] ## Example 5
+
+arrOut = arrInt[:]
+
+arrZeroPos = [nPos for nPos, nElem in enumerate(arrInt) if nElem == 0]
+
+if len(arrZeroPos) == 0:
+ print (arrOut)
+else:
+ for nPos in arrZeroPos[::-1]:
+ arrOut.insert(nPos, 0)
+ print (arrOut[:len(arrInt)])
diff --git a/challenge-333/ulrich-rieke/cpp/ch-1.cpp b/challenge-333/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..dff850ba55 --- /dev/null +++ b/challenge-333/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,47 @@ +#include <string>
+#include <vector>
+#include <utility>
+#include <regex>
+#include <iostream>
+#include <algorithm>
+using namespace std::string_literals ;
+
+bool on_straight_line( const std::vector<std::pair<int , int>> & coords ) {
+ int first_x = coords[0].first ;
+ int first_y = coords[0].second ;
+ if ( std::all_of( coords.begin( ) , coords.end( ) , [first_x]( auto p ) {
+ return p.first == first_x ; } ) || std::all_of( coords.begin( ) ,
+ coords.end( ) , [first_y]( auto b ) { return b.second ==
+ first_y ; }))
+ return true ;
+ else {
+ double slope_one = (static_cast<double>(coords[1].second) -
+ static_cast<double>(coords[0].second )) / (static_cast<double>(
+ coords[1].first) - static_cast<double>(coords[0].first )) ;
+ double slope_two = (static_cast<double>(coords[2].second) -
+ static_cast<double>(coords[1].second )) / (static_cast<double>(
+ coords[2].first) - static_cast<double>(coords[1].first )) ;
+ return slope_one == slope_two ;
+ }
+}
+
+int main( ) {
+ std::cout << "Enter 3 coordinates in brackets!\n" ;
+ std::string inputline ;
+ std::getline( std::cin , inputline ) ;
+ auto pattern {R"(\d+)"s} ;
+ auto re = std::regex { pattern } ;
+ std::vector<std::pair<int , int>> coordinates ;
+ std::vector<std::string> numbers ;
+ auto end = std::sregex_token_iterator{} ;
+ for ( auto it = std::sregex_token_iterator { std::begin( inputline ) ,
+ std::end( inputline ) , re } ; it != end ; ++it ) {
+ numbers.push_back( *it ) ;
+ }
+ for ( int i = 0 ; i < numbers.size( ) - 1 ; i += 2) {
+ coordinates.push_back( std::make_pair( std::stoi( numbers[i] ) ,
+ std::stoi( numbers[i + 1] ) )) ;
+ }
+ std::cout << std::boolalpha << on_straight_line( coordinates ) << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-333/ulrich-rieke/cpp/ch-2.cpp b/challenge-333/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..2894348b28 --- /dev/null +++ b/challenge-333/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,39 @@ +#include <string>
+#include <sstream>
+#include <vector>
+#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 some integers separated by whitespace!\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> afterDoubling ;
+ for ( auto it = numbers.begin( ) ; it != numbers.end( ) ; ++it ) {
+ if ( *it == 0 ) {
+ afterDoubling.push_back( 0 ) ;
+ afterDoubling.push_back( 0 ) ;
+ }
+ else
+ afterDoubling.push_back( *it ) ;
+ }
+ std::cout << "( " ;
+ for ( int i = 0 ; i < numbers.size( ) ; i++ ) {
+ std::cout << afterDoubling[i] << ' ' ;
+ }
+ std::cout << ")\n" ;
+ return 0 ;
+}
+
diff --git a/challenge-333/ulrich-rieke/haskell/ch-1.hs b/challenge-333/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..8100b4a2fb --- /dev/null +++ b/challenge-333/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,36 @@ +module Challenge333
+ where
+import Data.Char( isDigit )
+import Data.List.Split ( chunksOf )
+import Data.List ( (!!) )
+
+parseEntryLine :: String -> [(Int , Int)]
+parseEntryLine line =
+ let parts = words line
+ numbers = map (filter isDigit ) parts
+ relevant = filter ( not . null ) numbers
+ nums = map read relevant
+ coords = chunksOf 2 nums
+ in map (\subli -> (head subli , last subli) ) coords
+
+onStraightLine :: [(Int , Int)] -> Bool
+onStraightLine coordinates = all (\p -> fst p == ( fst $ head coordinates ))
+ coordinates || all (\p -> snd p == ( snd $ head coordinates )) coordinates ||
+ slopeOne == slopeTwo
+ where
+ slopeOne :: Double
+ slopeOne = (( fromIntegral $ snd ( coordinates !! 1 ) ) - ( fromIntegral $
+ snd ( coordinates !! 0 ) )) / (( fromIntegral $ fst ( coordinates !! 1 )) -
+ (fromIntegral $ fst ( coordinates !! 0 ) ) )
+ slopeTwo = (( fromIntegral $ snd ( coordinates !! 2 ) ) - ( fromIntegral $
+ snd ( coordinates !! 1 ) )) / (( fromIntegral $ fst ( coordinates !! 2 )) -
+ (fromIntegral $ fst ( coordinates !! 1 ) ) )
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some coordinates in brackets separated by comma and space!"
+ numberLine <- getLine
+ print $ onStraightLine $ parseEntryLine numberLine
+
+
+
diff --git a/challenge-333/ulrich-rieke/haskell/ch-2.hs b/challenge-333/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..0927419ce5 --- /dev/null +++ b/challenge-333/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,13 @@ +module Challenge333_2
+ where
+
+solution :: [Int] -> [Int]
+solution list = take ( length list ) $ foldl1 ( ++ ) $ map (\i -> if i == 0
+ then replicate 2 0 else [i] ) list
+
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some integers separated by whitespace!"
+ numberline <- getLine
+ print $ solution $ map read $ words numberline
diff --git a/challenge-333/ulrich-rieke/perl/ch-1.pl b/challenge-333/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..89e0b9769e --- /dev/null +++ b/challenge-333/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter some coordinates in brackets!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @parts = split( /\]\s*\,\s*\[/ , $line ) ;
+my @pairs ;
+for my $pair( @parts ) {
+ if ( $pair =~ /(\d+)\s*\,\s*(\d+)/ ) {
+ push( @pairs , [$1 , $2] ) ;
+ }
+}
+if ( on_straight_line(\@pairs)) {
+ say "true" ;
+}
+else {
+ say "false" ;
+}
+
+sub on_straight_line {
+ my $coords = shift ;
+ if (($coords->[1]->[1] == $coords->[0]->[1] && $coords->[2]->[1] ==
+ $coords->[1]->[1] ) || ( $coords->[1]->[0] == $coords->[0]->[0] &&
+ $coords->[2]->[0] == $coords->[1]->[0] )) {
+ return 1 ;
+ }
+ else {
+ my $slope_one = ($coords->[1]->[1] - $coords->[0]->[1] ) /
+ ($coords->[1]->[0] - $coords->[0]->[0] ) ;
+ my $slope_two = ( $coords->[2]->[1] - $coords->[1]->[1] ) / (
+ $coords->[2]->[0] - $coords->[1]->[0] ) ;
+ if ( $slope_one == $slope_two ) {
+ return 1 ;
+ }
+ else {
+ return 0 ;
+ }
+ }
+}
+
diff --git a/challenge-333/ulrich-rieke/perl/ch-2.pl b/challenge-333/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..9a91827e69 --- /dev/null +++ b/challenge-333/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter some integers separated by whitespace!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s+/ , $line ) ;
+my @after_doubling ;
+my $len = scalar( @numbers ) ;
+for my $n ( @numbers ) {
+ if ( $n == 0 ) {
+ push( @after_doubling , 0 ) ;
+ push( @after_doubling , 0 ) ;
+ }
+ else {
+ push( @after_doubling , $n ) ;
+ }
+}
+say join( ',' , @after_doubling[0..$len - 1] ) ;
diff --git a/challenge-333/ulrich-rieke/raku/ch-1.raku b/challenge-333/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..e713d999d9 --- /dev/null +++ b/challenge-333/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,27 @@ +use v6 ;
+
+say "Enter 3 coordinate pairs in brackets!" ;
+my $line = $*IN.get ;
+my @pairs ;
+my @parts = $line.split( /\] ',' \s+\[/ ) ;
+for @parts -> $pair {
+ if ($pair ~~ /(\d+)\s* ',' \s* (\d+) / ) {
+ my $numberpair = [+$0 , +$1] ;
+ @pairs.push( $numberpair ) ;
+ }
+}
+say on_straight_line( @pairs ) ;
+
+sub on_straight_line( @numbers ) {
+ if (@numbers[0][0] == @numbers[1][0] && @numbers[1][0] == @numbers[2][0] ||
+ @numbers[0][1] == @numbers[1][1] && @numbers[1][1] == @numbers[2][1] ) {
+ return True ;
+ }
+ else {
+ my $slope_one = (@numbers[1][1] - @numbers[0][1]) / (@numbers[1][0] -
+ @numbers[0][0] ) ;
+ my $slope_two = (@numbers[2][1] - @numbers[1][1] ) / (@numbers[2][0] -
+ @numbers[1][0] ) ;
+ return $slope_one == $slope_two ;
+ }
+}
diff --git a/challenge-333/ulrich-rieke/raku/ch-2.raku b/challenge-333/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..ae856c1613 --- /dev/null +++ b/challenge-333/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,17 @@ +use v6 ;
+
+say "Enter some integers separated by whitespace!" ;
+my $line = $*IN.get ;
+my @numbers = $line.words.map( {.Int} ) ;
+my @after_doubling ;
+for @numbers -> $n {
+ if ( $n == 0 ) {
+ @after_doubling.push( 0 ) ;
+ @after_doubling.push( 0 ) ;
+ }
+ else {
+ @after_doubling.push( $n ) ;
+ }
+}
+my $len = @numbers.elems ;
+say @after_doubling[0..$len - 1].join( ',' ) ;
diff --git a/challenge-333/ulrich-rieke/rust/ch-1.rs b/challenge-333/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..7a6096aad0 --- /dev/null +++ b/challenge-333/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,35 @@ +use std::io ; +use regex::Regex ; + +fn parse_pair( bracket : &str ) -> (i32 , i32) { + let re = Regex::new( r"([0-9]+)").unwrap( ) ; + let numbers : Vec<i32> = re.find_iter( bracket ).map( |m| { + let found = m.as_str( ) ; + let num : i32 = found.parse::<i32>( ).unwrap( ) ; + num + }).collect( ) ; + (numbers[0] , numbers[1]) +} + +fn on_straight_line( points : Vec<(i32 , i32)> ) -> bool { + points.iter( ).all( |p| p.0 == points[0].0 || p.1 == points[0].1 ) || + { let first_slope : f32 = ((points[1].1 as f32) - (points[0].1 as f32)) / + ((points[1].0 as f32) - (points[0].0 as f32 )) ; + let second_slope : f32 = ((points[2].1 as f32 ) - (points[1].1 as f32 )) / + ((points[2].0 as f32) - ( points[1].0 as f32 ) ) ; + first_slope == second_slope + } +} + +fn main() { + println!("Enter 3 coordinates as a pair of integers in brackets!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let re = Regex::new( r"\[\s*([0-9]+)\s*\,\s*([0-9]+)\]").unwrap( ) ; + let trimmed = inline.trim( ) ; + let parts : Vec<&str> = re.find_iter(trimmed).map( |m| m.as_str( )). + collect( ) ; + let coordinates : Vec<(i32 , i32)> = parts.into_iter( ).map( |s| + parse_pair( s ) ).collect( ) ; + println!("{}" , on_straight_line( coordinates ) ) ; +} diff --git a/challenge-333/ulrich-rieke/rust/ch-2.rs b/challenge-333/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..97b83455dd --- /dev/null +++ b/challenge-333/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,22 @@ +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 after_doubling : Vec<i32> = Vec::new( ) ; + let len : usize = numbers.len( ) ; + for n in numbers { + if n == 0 { + after_doubling.push( 0 ) ; + after_doubling.push( 0 ) ; + } + else { + after_doubling.push( n ) ; + } + } + println!("{:?}" , after_doubling.into_iter( ).take( len ). + collect::<Vec<i32>>( ) ) ; +} diff --git a/stats/pwc-challenge-332.json b/stats/pwc-challenge-332.json new file mode 100644 index 0000000000..5176d0ef61 --- /dev/null +++ b/stats/pwc-challenge-332.json @@ -0,0 +1,593 @@ +{ + "chart" : { + "type" : "column" + }, + "drilldown" : { + "series" : [ + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Ali Moradi", + "name" : "Ali Moradi" + }, + { + "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 + ] + ], + "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" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 10 + ] + ], + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" + }, + { + "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", + 2 + ] + ], + "id" : "mauke", + "name" : "mauke" + }, + { + "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" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Simon Proctor", + "name" : "Simon Proctor" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Solathian", + "name" : "Solathian" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Thomas Kohler", + "name" : "Thomas Kohler" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke" + }, + { + "data" : [ + [ + "Perl", |
