diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-07-11 09:52:16 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-07-11 09:52:16 +0100 |
| commit | 2b586bbcfa9f30c6f6548aaadddd665b2d80198f (patch) | |
| tree | 6d676f382277e78f35cb328e94898ecc9efb687a | |
| parent | 7393288e47338ee64ed0452c497020e8c8d1af53 (diff) | |
| download | perlweeklychallenge-club-2b586bbcfa9f30c6f6548aaadddd665b2d80198f.tar.gz perlweeklychallenge-club-2b586bbcfa9f30c6f6548aaadddd665b2d80198f.tar.bz2 perlweeklychallenge-club-2b586bbcfa9f30c6f6548aaadddd665b2d80198f.zip | |
- Added solutions by Robert DiCicco.
- Added solutions by Laurent Rosenfeld.
- Added solutions by Ulrich Rieke.
- Added solutions by Jaldhar H. Vyas.
- Added solutions by W. Luis Mochan.
- Added solutions by Robbie Hatley.
- Added solutions by Mark Anderson.
- Added solutions by David Ferrone.
- Added solutions by Andreas Voegele.
- Added solutions by Lubos Kolouch.
- Added solutions by Thomas Kohler.
38 files changed, 4383 insertions, 3344 deletions
diff --git a/challenge-225/eric-cheung/python/ch-1.py b/challenge-225/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..f0095f08e1 --- /dev/null +++ b/challenge-225/eric-cheung/python/ch-1.py @@ -0,0 +1,8 @@ +
+## arrWordList = ["Perl and Raku belong to the same family.", "I love Perl.", "The Perl and Raku Conference."] ## Example 1
+arrWordList = ["The Weekly Challenge.", "Python is the most popular guest language.", "Team PWC has over 300 members."] ## Example 2
+
+arrWordLen = [len(wordLoop.split()) for wordLoop in arrWordList]
+nMaxWordLen = max(arrWordLen)
+
+print (nMaxWordLen)
diff --git a/challenge-225/eric-cheung/python/ch-2.py b/challenge-225/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..64e98389f4 --- /dev/null +++ b/challenge-225/eric-cheung/python/ch-2.py @@ -0,0 +1,19 @@ +
+## arrInt = [10, 4, 8, 3] ## Example 1
+## arrInt = [1] ## Example 2
+arrInt = [1, 2, 3, 4, 5] ## Example 3
+
+arrLeft = [0]
+arrRight = [0]
+
+for nIndx in range(len(arrInt) - 1):
+ arrLeft.append(arrLeft[-1] + arrInt[nIndx])
+ arrRight.append(arrRight[-1] + arrInt[len(arrInt) - nIndx - 1])
+
+arrRight.reverse()
+
+arrLeftRightSumDiff = [abs(arrLeft[nIndx] - arrRight[nIndx]) for nIndx in range(len(arrLeft))]
+
+## print (arrLeft)
+## print (arrRight)
+print (arrLeftRightSumDiff)
diff --git a/challenge-225/laurent-rosenfeld/blog.txt b/challenge-225/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..81e5655f24 --- /dev/null +++ b/challenge-225/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/07/perl-weekly-challenge-225-max-words.html diff --git a/challenge-225/laurent-rosenfeld/perl/ch-1.pl b/challenge-225/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..fa083ef410 --- /dev/null +++ b/challenge-225/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,25 @@ +use strict; +use warnings; +use feature 'say'; + +sub max_words { + my $max = 0; + for my $sentence (@_) { + my $cw = scalar split /\s+/, $sentence; + $max = $cw if $cw > $max; + } + return $max; +} + +my @tests = ( + ["The quick brown fox jumps over the lazy dog", + "Lorem ipsum dolor sit amet"], + ["Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."], + ["The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."]); +for my $test (@tests) { + say max_words @$test; +} diff --git a/challenge-225/laurent-rosenfeld/raku/ch-1.raku b/challenge-225/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..fa6cf6a104 --- /dev/null +++ b/challenge-225/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,21 @@ +sub max-words (@sentences) { + my $max = 0; + for @sentences -> $sentence { + my $cw = $sentence.words.elems; + $max = $cw if $cw > $max; + } + return $max; +} + +my @tests = + ("The quick brown fox jumps over the lazy dog", + "Lorem ipsum dolor sit amet"), + ("Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."), + ("The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."); +for @tests -> @test { + say max-words @test; +} diff --git a/challenge-225/robert-dicicco/julia/ch-1.jl b/challenge-225/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..806b68291f --- /dev/null +++ b/challenge-225/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,51 @@ +#!/usr/bin/env julia +#= +----------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-07-10 +Challenge 225 Task 1 Max Words ( Julia ) +----------------------------------- +=# + +using Printf + +lists = [["Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."], + ["The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."]] + +max_num = 0 + +for lst in lists + global max_num + @printf("Input: @list = %s\n",lst) + cnt = 1 + sz = length(lst) + while cnt < sz + words = split(lst[cnt]) + ln = length(words) + if ln > max_num + max_num = ln + end + cnt += 1 + end + @printf("Output: %d\n\n", max_num) + max_num = 0 +end + +#= +----------------------------------- +SAMPLE OUTPUT +julia .\MaxWords.jl +Input: @list = ["Perl and Raku belong to the same family.", "I love Perl.", "The Perl and Raku Conference."] +Output: 8 + +Input: @list = ["The Weekly Challenge.", "Python is the most popular guest language.", "Team PWC has over 300 members."] +Output: 7 +----------------------------------- +=# + + + diff --git a/challenge-225/robert-dicicco/perl/ch-1.pl b/challenge-225/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..a5e7a2020d --- /dev/null +++ b/challenge-225/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +=begin comment +------------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-07-10 +Challenge 225 Task 1 Max Words ( Perl ) +------------------------------------------- +=cut +use strict; +use warnings; +use feature 'say'; + +my @lists = (["Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."], + ["The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."]); + +my $max_num = 0; +my $num = 0; + +sub count_words { + my $num; + my $lst = shift; + $num++ while $lst =~ /\S+/g; + return $num; +} + +for my $lst (@lists) { + say "Input: \@list = (",@$lst,")"; + for my $wds (@$lst) { + $num = count_words($wds); + if ($num > $max_num) { + $max_num = $num; + } + } + say "Output: $max_num\n"; + $max_num = 0; + $num = 0; +} + +=begin comment +------------------------------------------- +SAMPLE OUTPUT +perl .\MaxWords.pl +Input: @list = (Perl and Raku belong to the same family.I love Perl.The Perl and Raku Conference.) +Output: 8 + +Input: @list = (The Weekly Challenge.Python is the most popular guest language.Team PWC has over 300 members.) +Output: 7 +------------------------------------------- +=cut + + diff --git a/challenge-225/robert-dicicco/python/ch-1.py b/challenge-225/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..a5822d23ef --- /dev/null +++ b/challenge-225/robert-dicicco/python/ch-1.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# ----------------------------------- +# AUTHOR: Robert DiCicco +# DATE : 2023-07-10 +# Challenge 225 Task 1 Max Words ( Python ) +# ----------------------------------- +lists = [["Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."], + ["The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."]] + +max_num = 0 +for lst in lists: + print("Input: @list = ",lst) + cnt = 0 + sz = len(lst) + while cnt < sz: + words = lst[cnt].split() + num = len(words) + if num > max_num: + max_num = num + cnt += 1 + print(f"Output: {max_num}\n") + max_num = 0 + +#----------------------------------- +# SAMPLE OUTPUT +# python .\MaxWords.py + +# Input: @list = ['Perl and Raku belong to the same family.', 'I love Perl.', 'The Perl and Raku Conference.'] +# Output: 8 + +# Input: @list = ['The Weekly Challenge.', 'Python is the most popular guest language.', 'Team PWC has over 300 members.'] +# Output: 7 +#----------------------------------- + + diff --git a/challenge-225/robert-dicicco/raku/ch-1.raku b/challenge-225/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..e5b84bfcff --- /dev/null +++ b/challenge-225/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,47 @@ +#!/usr/bin/env raku +=begin comment +----------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-07-10 +Challenge 225 Task 1 Max Words ( Raku ) +----------------------------------- +=end comment +use v6; + +my @lists = [["Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."], + ["The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."]]; + +my $max_num = 0; +my $num = 0; + +for (@lists) -> $lst { + say "Input: \@list = ($lst)"; + my $cnt = 0; + while $cnt < $lst.elems { + $num = $lst[$cnt].comb(/\w+/).elems; + if $num > $max_num { + $max_num = $num; + } + $cnt++; + } + say "Output: $max_num\n"; + $max_num = 0; + $num = 0; +} + +=begin comment +----------------------------------- +raku MaxWords.rk +Input: @list = (Perl and Raku belong to the same family. I love Perl. The Perl and Raku Conference.) +Output: 8 + +Input: @list = (The Weekly Challenge. Python is the most popular guest language. Team PWC has over 300 members.) +Output: 7 +----------------------------------- +=end comment + + diff --git a/challenge-225/robert-dicicco/ruby/ch-1.rb b/challenge-225/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..6b60ffc6aa --- /dev/null +++ b/challenge-225/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby +=begin +----------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-07-10 +Challenge 225 Task 1 Max Words ( Ruby ) +----------------------------------- +=end + +lists = [["Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."], + ["The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."]] + +max_num = 0 + +lists.each do |lst| + puts("Input: @list = #{lst}") + cnt = 0 + while cnt < lst.length + sz = lst[cnt].split.to_a; + if sz.length > max_num + max_num = sz.length + end + cnt += 1 + end + puts("Output: #{max_num}\n\n") + max_num = 0 +end + +=begin +----------------------------------- +ruby .\MaxWords.rb +Input: @list = ["Perl and Raku belong to the same family.", "I love Perl.", "The Perl and Raku Conference."] +Output: 8 + +Input: @list = ["The Weekly Challenge.", "Python is the most popular guest language.", "Team PWC has over 300 members."] +Output: 7 +----------------------------------- +=end + + diff --git a/challenge-225/ulrich-rieke/cpp/ch-1.cpp b/challenge-225/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..46258d8f48 --- /dev/null +++ b/challenge-225/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,42 @@ +#include <vector> +#include <iostream> +#include <string> +#include <algorithm> + +std::vector<std::string> split( const std::string & startline , + const std::string & sep ) { + std::vector<std::string> separated ; + std::string::size_type start { 0 } ; + std::string::size_type pos ; + do { + pos = startline.find_first_of( sep , start ) ; + separated.push_back( startline.substr(start , pos - start )) ; + start = pos + 1 ; + } while ( pos != std::string::npos ) ; + return separated ; +} + +int main( ) { + std::cout << "Enter some sentences, enter fin to end!\n" ; + std::vector<std::string> sentences ; + std::string line ; + std::getline( std::cin , line ) ; + while ( line != "fin" ) { + if (line.substr(0 , 1 ) == " " || line.back( ) == ' ' ) { + std::cout << "There should be no spaces at the beginning and the end!\n" ; + std::cout << "Re-enter!\n" ; + } + else { + sentences.push_back( line ) ; + } + std::getline( std::cin , line ) ; + } + std::vector<int> lengths ; + for ( auto s : sentences ) { + std::vector<std::string> words ( split( s , " " ) ) ; + lengths.push_back( words.size( ) ) ; + } + std::cout << *std::max_element( lengths.begin( ) , lengths.end( ) ) << + std::endl ; + return 0 ; +} diff --git a/challenge-225/ulrich-rieke/cpp/ch-2.cpp b/challenge-225/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..6db2f84360 --- /dev/null +++ b/challenge-225/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,78 @@ +#include <iostream> +#include <string> +#include <vector> + +std::vector<std::string> split( const std::string & startline , + const std::string & sep ) { + std::vector<std::string> separated ; + std::string::size_type start { 0 } ; + std::string::size_type pos ; + do { + pos = startline.find_first_of( sep , start ) ; + separated.push_back( startline.substr(start , pos - start )) ; + start = pos + 1 ; + } while ( pos != std::string::npos ) ; + return separated ; +} + +std::vector<int> find_left_array( const std::vector<int> & numbers ) { + int len = numbers.size( ) ; + int limit = len / 2 ; + std::vector<int> left_array ; + left_array.push_back( 0 ) ; + int left_sum = 0 ; + for ( int i = 0 ; i < limit + 1 ; i++ ) { + left_sum += numbers[ i ] ; + left_array.push_back( left_sum ) ; + } + return left_array ; +} + +std::vector<int> find_right_array( const std::vector<int> & numbers ) { + int len = numbers.size( ) ; + int left_limit = 0 ; + if ( len % 2 == 1 ) + left_limit = len / 2 ; + else + left_limit = len / 2 - 1 ; + std::vector<int> right_array ; + int right_sum = 0 ; + for ( int i = left_limit ; i < len ; i++ ) + right_sum += numbers[ i ] ; + right_array.push_back( right_sum ) ; + for ( int i = left_limit ; i < len ; i++ ) { + right_sum -= numbers[ i ] ; + right_array.push_back( right_sum ) ; + } + right_array.push_back( 0 ) ; + return right_array ; +} + +int main( ) { + std::cout << "Enter some integers, separated by blanks!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::vector<std::string> numberstrings( split( line , " " ) ) ; + std::vector<int> numbers ; + for ( auto s : numberstrings ) + numbers.push_back( std::stoi( s ) ) ; + if (numbers.size( ) == 1) + std::cout << "(0)\n" ; + else { + std::vector<int> result ; + std::vector<int> left_array( find_left_array( numbers )) ; + std::vector<int> right_array( find_right_array( numbers )) ; + for ( int i = 0 ; i < left_array.size( ) ; i++ ) { + result.push_back( std::abs( left_array[ i ] - right_array[ i ] )) ; + } + std::cout << "(" ; + for ( int i : result ) { + std::cout << i ; + if ( i != result.back( ) ) + std::cout << "," ; + else + std::cout << ")\n" ; + } + } + return 0 ; +} diff --git a/challenge-225/ulrich-rieke/haskell/ch-1.hs b/challenge-225/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..adcbf6939e --- /dev/null +++ b/challenge-225/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,32 @@ +module Challenge225 + where +import Data.Char( isSpace ) +import Control.Monad.State + +isValid :: String -> Bool +isValid str = (not $ isSpace $ head str) && ( not $ isSpace $ last str ) + +askForInput :: IO String +askForInput = do + putStrLn "Enter a sentence without trailing spaces, fin to end!" + line <- getLine + if (isValid line ) then pure line + else + askForInput + +enterStrings :: StateT [String] ( IO )[String] +enterStrings = do + sentences <- get + sentence <- lift $ askForInput + if sentence == "fin" then return sentences + else do + modify (++ [sentence]) + enterStrings + +solution :: [String] -> Int +solution strings = maximum $ map ( length . words ) strings + +main :: IO ( ) +main = do + strings <- execStateT enterStrings [] + print $ solution strings diff --git a/challenge-225/ulrich-rieke/haskell/ch-2.hs b/challenge-225/ulrich-rieke/haskell/ch-2.hs new file mode 100644 index 0000000000..0eb711011e --- /dev/null +++ b/challenge-225/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,33 @@ +module Challenge225_2 + where + +find_left_array :: [Int] -> [Int] +find_left_array list = [0] ++ map (\i -> sum $ take i list ) [1..limit + 1] +where + limit :: Int + limit = div ( length list ) 2 + +find_right_array :: [Int] -> [Int] +find_right_array list = map (\i -> sum $ drop i rightPart ) [0..length +rightPart - 1] ++ [0] +where + l :: Int + l = length list + left_limit :: Int + left_limit = if odd l then div l 2 else div l 2 - 1 + rightPart :: [Int] + rightPart = drop left_limit list + +solution :: [Int] -> [Int] +solution list + |length list == 1 = [0] + |otherwise = zipWith op (find_left_array list) ( find_right_array list ) + where + op :: Int -> Int -> Int + op a b = abs( a - b ) + +main :: IO ( ) +main = do + putStrLn "Enter some digits, separated by blanks!" ; + numberstrings <- getLine + print $ solution $ map read $ words numberstrings diff --git a/challenge-225/ulrich-rieke/perl/ch-1.pl b/challenge-225/ulrich-rieke/perl/ch-1.pl new file mode 100644 index 0000000000..062ee4e50e --- /dev/null +++ b/challenge-225/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; +use List::Util qw ( max ) ; + +say "Please enter some sentences, fin to end entry!" ; +my @sentences ; +my $line = <STDIN> ; +chomp $line ; +while ( $line ne "fin" ) { + if ( $line !~ /^\S.+\S$/ ) { + say "There should be no trailing spaces at the beginning and the end!" ; + say "Re-enter!" ; + } + else { + push @sentences, $line ; + } + $line = <STDIN> ; + chomp $line ; +} +my @lengths ; +for my $sentence ( @sentences ) { + my @words = split( /\s/ , $sentence ) ; + push @lengths, scalar( @words ) ; +} +say max( @lengths ) ; diff --git a/challenge-225/ulrich-rieke/perl/ch-2.pl b/challenge-225/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..3ae0077215 --- /dev/null +++ b/challenge-225/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +sub find_left_array { + my $array = shift ; + my @left_array ; + my $len = scalar( @$array ) ; + my $limit = int( $len / 2 ) ; + push @left_array , 0 ; + my $left_sum = 0 ; + for my $i ( 0..$limit ) { + $left_sum += $array->[ $i ] ; + push @left_array, $left_sum ; + } + return @left_array ; +} + +sub find_right_array { + my $array = shift ; + my @right_array ; + my $len = scalar( @$array ) ; + my $left_limit ; + if ( $len % 2 == 1 ) { + $left_limit = int( $len / 2 ) ; + } + else { + $left_limit = int( $len / 2 ) - 1 ; + } + my $right_sum = 0 ; + for my $i( $left_limit..$len - 1 ) { + $right_sum += $array->[ $i ] ; + } + push @right_array , $right_sum ; + for my $i( $left_limit..$len - 1 ) { + $right_sum -= $array->[ $i ] ; + push @right_array , $right_sum ; + } + push @right_array , 0 ; + return @right_array ; +} + +say "Enter some integers, separated by blanks!" ; +my $line = <STDIN> ; +chomp $line ; +my @numbers = split( /\s/ , $line ) ; +my $len = scalar( @numbers ) ; +if ( $len == 1 ) { + say "(0)" ; +} +else { + my @result ; + my @left_array = find_left_array( \@numbers ) ; + my @right_array = find_right_array( \@numbers ) ; + for my $i (0..scalar( @left_array) - 1 ) { + push @result , abs( $left_array[ $i ] - $right_array[ $i ] ) ; + } + say "(" . join( ',' , @result ) . ")" ; +} diff --git a/challenge-225/ulrich-rieke/raku/ch-1.raku b/challenge-225/ulrich-rieke/raku/ch-1.raku new file mode 100644 index 0000000000..a72a3486eb --- /dev/null +++ b/challenge-225/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,15 @@ +use v6 ; + +say "Enter some sentences! Enter fin to end!" ; +my @sentences ; +my $line = $*IN.get ; +while ( $line ne "fin" ) { + if ( $line ~~ /^\S .+ \S$/ ) { + @sentences.push( $line ) ; + } + else { + say "No leading or trailing spaces, please! Re-enter!" ; + } + $line = $*IN.get ; +} +say @sentences.map( {.words} ).map( {.elems} ).max ; diff --git a/challenge-225/ulrich-rieke/raku/ch-2.raku b/challenge-225/ulrich-rieke/raku/ch-2.raku new file mode 100644 index 0000000000..e8a3035feb --- /dev/null +++ b/challenge-225/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,56 @@ +use v6 ; + +sub find_left_array( @array ) { + my @left_array ; + my $len = @array.elems ; + my $limit = $len div 2 ; + @left_array.push( 0 ) ; + my $left_sum = 0 ; + for (0..$limit) -> $i { + $left_sum += @array[ $i ] ; + @left_array.push( $left_sum ) ; + } + return @left_array ; +} + +sub find_right_array( @array ) { + my @right_array ; + my $len = @array.elems ; + my $left_limit ; + if ( $len % 2 == 1 ) { + $left_limit = $len div 2 ; + } + else { + $left_limit = ( $len div 2 ) - 1 ; + } + my $right_sum = 0 ; + for ($left_limit..$len - 1) -> $i { + $right_sum += @array[ $i ] ; + } + @right_array.push( $right_sum ) ; + for ($left_limit..$len - 1 ) -> $i { + $right_sum -= @array[ $i ] ; + @right_array.push( $right_sum ) ; + } + @right_array.push( 0 ) ; + return @right_array ; +} + +sub my_op( $num1 , $num2 ) { + return abs( $num1 - $num2 ) ; +} + +say "Find some integers, separated by blanks!" ; +my $line = $*IN.get ; +my @numbers = $line.words.map( {.Int } ) ; +my $len = @numbers.elems ; +if ( $len == 1 ) { + say "(0)" ; +} +else { + my @result ; + my @left_array = find_left_array( @numbers ) ; + my @right_array = find_right_array( @numbers ) ; + say "(" ~ join( "," , zip( @left_array, @right_array , :with( &my_op ) )) + ~ ")" ; +} diff --git a/challenge-225/ulrich-rieke/rust/ch-1.rs b/challenge-225/ulrich-rieke/rust/ch-1.rs new file mode 100644 index 0000000000..77707664ed --- /dev/null +++ b/challenge-225/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,26 @@ +use std::io ; +use std::io::BufRead ; + +fn main() -> io::Result<( )> { + println!("Enter some sentences, <return> to end!"); + let mut lines = io::stdin( ).lock( ).lines( ) ; + let mut all_input : String = String::new( ) ; + while let Some( line ) = lines.next( ) { + let last_input = line.unwrap( ) ; + if last_input.len( ) == 0 { + break ; + } + else { + all_input.push_str("\n" ) ; + } + all |
