diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-10-16 23:39:40 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-10-16 23:39:40 +0100 |
| commit | eb89c85d8f90b18bb075d6bc49e009e38294ad39 (patch) | |
| tree | 78c361e3755dd8973a0aeeb3bec1e945ff210c43 | |
| parent | 9c3e2ca8f3eb9a2dd8ae0073b36816f21367a3b6 (diff) | |
| download | perlweeklychallenge-club-eb89c85d8f90b18bb075d6bc49e009e38294ad39.tar.gz perlweeklychallenge-club-eb89c85d8f90b18bb075d6bc49e009e38294ad39.tar.bz2 perlweeklychallenge-club-eb89c85d8f90b18bb075d6bc49e009e38294ad39.zip | |
- Added solutions by Robert DiCicco.
- Added solutions by Ulrich Rieke.
- Added solutions by Eric Cheung.
- Added solutions by W. Luis Mochan.
- Added solutions by Matthias Muth.
- Added solutions by rcmlz.
- Added solutions by Niels van Dijke.
- Added solutions by E. Choroba.
- Added solutions by Mark Anderson.
- Added solutions by Jaldhar H. Vyas.
- Added solutions by PokGoPun.
- Added solutions by David Ferrone.
- Added solutions by Dave Jacoby.
- Added solutions by Peter Meszaros.
- Added solutions by Thomas Kohler.
39 files changed, 4231 insertions, 3363 deletions
diff --git a/challenge-239/eric-cheung/python/ch-1.py b/challenge-239/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..7d0991df77 --- /dev/null +++ b/challenge-239/eric-cheung/python/ch-1.py @@ -0,0 +1,14 @@ +
+## Example 1
+## arrInput_01 = ["ab", "c"]
+## arrInput_02 = ["a", "bc"]
+
+## Example 2
+## arrInput_01 = ["ab", "c"]
+## arrInput_02 = ["ac", "b"]
+
+## Example 3
+arrInput_01 = ["ab", "cd", "e"]
+arrInput_02 = ["abcde"]
+
+print ("".join(arrInput_01) == "".join(arrInput_02))
diff --git a/challenge-239/eric-cheung/python/ch-2.py b/challenge-239/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..dac1eb5222 --- /dev/null +++ b/challenge-239/eric-cheung/python/ch-2.py @@ -0,0 +1,21 @@ +
+## Example 1
+## arrStr = ["ad", "bd", "aaab", "baa", "badab"]
+## strAllowed = "ab"
+
+## Example 2
+## arrStr = ["a", "b", "c", "ab", "ac", "bc", "abc"]
+## strAllowed = "abc"
+
+## Example 3
+arrStr = ["cc", "acd", "b", "ba", "bac", "bad", "ac", "d"]
+strAllowed = "cad"
+
+arrOutput = []
+
+for strLoop in arrStr:
+ arrTemp = [charLoop for charLoop in set(strLoop) if charLoop not in strAllowed]
+ if len(arrTemp) == 0:
+ arrOutput.append(strLoop)
+
+print (len(arrOutput))
diff --git a/challenge-239/perlboy1967/perl/ch1.pl b/challenge-239/perlboy1967/perl/ch-1.pl index e9e0ed52fb..e9e0ed52fb 100755 --- a/challenge-239/perlboy1967/perl/ch1.pl +++ b/challenge-239/perlboy1967/perl/ch-1.pl diff --git a/challenge-239/perlboy1967/perl/ch2.pl b/challenge-239/perlboy1967/perl/ch-2.pl index de5d428e08..de5d428e08 100755 --- a/challenge-239/perlboy1967/perl/ch2.pl +++ b/challenge-239/perlboy1967/perl/ch-2.pl diff --git a/challenge-239/rcmlz/raku/ch-1.raku b/challenge-239/rcmlz/raku/ch-1.raku new file mode 100644 index 0000000000..d0dca8e548 --- /dev/null +++ b/challenge-239/rcmlz/raku/ch-1.raku @@ -0,0 +1,13 @@ +unit module rcmlz::raku::task-one:ver<0.0.1>:auth<github:rcmlz>:api<1>; + +# run in terminal: raku --optimize=3 -I challenge-nr239/rcmlz/raku/ -- test/challenge-nr239/raku/task-one.rakutest +# or raku --optimize=3 -I challenge-nr239 -- test/benchmark-scalabiity.raku --task=task-one --user=rcmlz --max-run-times=1,3,7 --max-problem=10 --v=True --test-before-benchmark=True --out-folder=/tmp nr239; cat /tmp/nr239_task-one.csv + +#|[ +You are given two arrays of strings. + +- Write a script to find out if the word created by concatenating the array elements is the same. +] +our sub solution(@input where @input.elems == 2) is export { + [eqv] @input.map: *.join; +}
\ No newline at end of file diff --git a/challenge-239/rcmlz/raku/ch-2.raku b/challenge-239/rcmlz/raku/ch-2.raku new file mode 100644 index 0000000000..0e1c1fa26b --- /dev/null +++ b/challenge-239/rcmlz/raku/ch-2.raku @@ -0,0 +1,15 @@ +unit module rcmlz::raku::task-two:ver<0.0.1>:auth<github:rcmlz>:api<1>; + +# run in terminal: raku --optimize=3 -I challenge-nr239/rcmlz/raku/ -- test/challenge-nr239/raku/task-two.rakutest +# or raku --optimize=3 -I challenge-nr239 -- test/benchmark-scalabiity.raku --task=task-two --user=rcmlz --max-run-times=1,3,7 --max-problem=10 --v=True --test-before-benchmark=True --out-folder=/tmp nr239; cat /tmp/nr239_task-two.csv + +#|[ +You are given an array of strings and allowed string having distinct characters. +A string is consistent if all characters in the string appearing in the string are allowed. + +- Write a script to return the number of consistent strings in the given array. +] +our sub solution([$allowed, *@input]) is export { + my $allowed-chars = $allowed.comb.Set; + [+] @input.map: *.comb.Set ⊆ $allowed-chars; +}
\ No newline at end of file diff --git a/challenge-239/robert-dicicco/julia/ch-1.jl b/challenge-239/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..e2a9562006 --- /dev/null +++ b/challenge-239/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,43 @@ +#!/usr/bin/env julia +#= +------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-10-16 +Challenge 239 Task 01 Same String ( Julia ) +------------------------------------ +=# +using Printf + +myarr1 = [["ab", "c"],["ab", "c"],["ab", "cd", "e"]] +myarr2 = [["a", "bc"],["ac", "b"],["abcde"]] + +cnt = 1 +while cnt <= length(myarr1) + global cnt + @printf("Input: @arr1 = %s\n",myarr1[cnt]) + @printf("\t@arr2 = %s\n", myarr2[cnt]) + join(myarr1[cnt],"") == join(myarr2[cnt],"") ? println("Output: true\n") : println("Output: false\n") + cnt += 1 +end + +#= +------------------------------------- +SAMPLE OUTPUT + +julia .\SameString.jl + +Input: @arr1 = ["ab", "c"] + @arr2 = ["a", "bc"] +Output: true + +Input: @arr1 = ["ab", "c"] + @arr2 = ["ac", "b"] +Output: false + +Input: @arr1 = ["ab", "cd", "e"] + @arr2 = ["abcde"] +Output: true +------------------------------------ +=# + + diff --git a/challenge-239/robert-dicicco/perl/ch-1.pl b/challenge-239/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..cf95400a8d --- /dev/null +++ b/challenge-239/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +=begin comment +------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-10-16 +Challenge 239 Task 01 Same String ( Perl ) +------------------------------------ +=cut +use v5.38; + +my @myarr1 = (["ab", "c"],["ab", "c"],["ab", "cd", "e"]); +my @myarr2 = (["a", "bc"],["ac", "b"],["abcde"]); +my ($arr1, $arr2,$arr1_val,$arr2_val); + +my $cnt = 0; +while ( $cnt < scalar @myarr1) { + say "Input: \@arr1 = [@{$myarr1[$cnt]}]"; + say "\t\@arr2 = [@{$myarr2[$cnt]}]"; + join("",@{$myarr1[$cnt]}) eq join("",@{$myarr2[$cnt]}) ? say "Output: true\n" : say "Output: false\n" ; + $cnt++; +} + +=begin comment +------------------------------------- +SAMPLE OUTPUT + +perl .\SameString.pl + +Input: @arr1 = [ab c] + @arr2 = [a bc] +Output: true + +Input: @arr1 = [ab c] + @arr2 = [ac b] +Output: false + +Input: @arr1 = [ab cd e] + @arr2 = [abcde] +Output: true +------------------------------------ +=cut + + + diff --git a/challenge-239/robert-dicicco/powershell/ch-1.psl b/challenge-239/robert-dicicco/powershell/ch-1.psl new file mode 100644 index 0000000000..c54cca7ffc --- /dev/null +++ b/challenge-239/robert-dicicco/powershell/ch-1.psl @@ -0,0 +1,24 @@ +#!/usr/bin/env powershell +<# +------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-10-16 +Challenge 239 Task 01 Same String ( Powershell ) +------------------------------------ + #> +$myarr1 = @( ("ab", "c"),("ab", "c"),("ab", "cd", "e") ) +$myarr2 = @( ("a", "bc"),("ac", "b"),("abcde") ) +$cnt = 0 + +while ($cnt -lt $myarr1.count) { + write-host "Input: @arr1 = [",$myarr1[$cnt],"]" + write-host "`t@arr2 = [",$myarr2[$cnt],"]" + if (-join($myarr1[$cnt]) -eq -join($myarr2[$cnt])){ + write-host "Output: true`n" + } else { + write-host "Output: false`n" + } + $cnt += 1 +} + + diff --git a/challenge-239/robert-dicicco/python/ch-1.py b/challenge-239/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..463ec64b6f --- /dev/null +++ b/challenge-239/robert-dicicco/python/ch-1.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +''' +------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-10-16 +Challenge 239 Task 01 Same String ( Python ) +------------------------------------ +''' + +myarr1 = [["ab", "c"],["ab", "c"],["ab", "cd", "e"]] +myarr2 = [["a", "bc"],["ac", "b"],["abcde"]] + +cnt = 0 + +while cnt < len(myarr1): + print(f"Input: @arr1 = {myarr1[cnt]}") + print(f"\t@arr2 = {myarr2[cnt]}") + if "".join(myarr1[cnt]) == "".join(myarr2[cnt]): + print("Output: true\n") + else: + print("Output: false\n") + + cnt += 1 + +''' +------------------------------------- +SAMPLE OUTPUT + +python .\SameString.py + +Input: @arr1 = ['ab', 'c'] + @arr2 = ['a', 'bc'] +Output: true + +Input: @arr1 = ['ab', 'c'] + @arr2 = ['ac', 'b'] +Output: false + +Input: @arr1 = ['ab', 'cd', 'e'] + @arr2 = ['abcde'] +Output: true +------------------------------------ +''' + + + diff --git a/challenge-239/robert-dicicco/raku/ch-1.raku b/challenge-239/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..8714f0d966 --- /dev/null +++ b/challenge-239/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,42 @@ +#!/usr/bin/env raku +=begin comment +------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-10-16 +Challenge 239 Task 01 Same String ( Raku ) +------------------------------------ +=end comment + +my @myarr1 = (["ab", "c"],["ab", "c"],["ab", "cd", "e"]); +my @myarr2 = (["a", "bc"],["ac", "b"],["abcde"]); + +my $cnt = 0; + +while $cnt < @myarr1.elems { + say "Input: \@arr1 = [@myarr1[$cnt]]"; + say "\t\@arr2 = [@myarr2[$cnt]]"; + @myarr1[$cnt].join eq @myarr2[$cnt].join ?? say "Output: true\n" !! say "Output: false\n"; + $cnt++; +} + +=begin comment +------------------------------------- +SAMPLE OUTPUT + +raku .\SameString.rk + +Input: @arr1 = [ab c] + @arr2 = [a bc] +Output: true + +Input: @arr1 = [ab c] + @arr2 = [ac b] +Output: false + +Input: @arr1 = [ab cd e] + @arr2 = [abcde] +Output: true +------------------------------------ +=end comment + + diff --git a/challenge-239/robert-dicicco/ruby/ch-1.rb b/challenge-239/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..1f1b87e048 --- /dev/null +++ b/challenge-239/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,43 @@ +#!/usr/bin/env ruby +=begin comment +------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-10-16 +Challenge 239 Task 01 Same String ( Ruby ) +------------------------------------ +=end comment + +myarr1 = [["ab", "c"],["ab", "c"],["ab", "cd", "e"]] +myarr2 = [["a", "bc"],["ac", "b"],["abcde"]] + +cnt = 0 + +while cnt < myarr1.length() + puts("Input: @arr1 = [#{myarr1[cnt]}]") + puts("\t@arr2 = [#{myarr2[cnt]}]") + myarr1[cnt].join == myarr2[cnt].join ? puts("Output: true\n\n") : puts("Output: false\n\n") + cnt += 1 +end + +=begin comment +------------------------------------- +SAMPLE OUTPUT + +ruby .\SameString.rb + +Input: @arr1 = [["ab", "c"]] + @arr2 = [["a", "bc"]] +Output: true + +Input: @arr1 = [["ab", "c"]] + @arr2 = [["ac", "b"]] +Output: false + +Input: @arr1 = [["ab", "cd", "e"]] + @arr2 = [["abcde"]] +Output: true +------------------------------------ +=end comment + + + diff --git a/challenge-239/robert-dicicco/tcl/ch-1.tcl b/challenge-239/robert-dicicco/tcl/ch-1.tcl new file mode 100644 index 0000000000..49d5f93f56 --- /dev/null +++ b/challenge-239/robert-dicicco/tcl/ch-1.tcl @@ -0,0 +1,49 @@ +#!/usr/bin/env tclsh +# ------------------------------------- +# AUTHOR: Robert DiCicco +# DATE : 2023-10-16 +# Challenge 239 Task 01 Same String ( Tcl ) +# ------------------------------------ + +set myarr1 {{"ab" "c"} {"ab" "c"} {"ab" "cd" "e"}} +set myarr2 {{"a" "bc"} {"ac" "b"} {"abcde"}} +set cnt 0 +while { $cnt < [llength $myarr1]} { + puts "Input: @arr1 = [lindex $myarr1 $cnt]" + puts "\t@arr2 = [lindex $myarr2 $cnt]" + set str1 "" + set str2 "" + foreach wd1 [lindex $myarr1 $cnt] { + append str1 $wd1 + } + foreach wd2 [lindex $myarr2 $cnt] { + append str2 $wd2 + } + if { $str1 == $str2 } { + puts "Output: true\n" + } else { + puts "Output: false\n" + } + + incr cnt +} + +# ------------------------------------- +# SAMPLE OUTPUT + +# tclsh .\SameString.tcl + +# Input: @arr1 = "ab" "c" +# @arr2 = "a" "bc" +# Output: true + +# Input: @arr1 = "ab" "c" +# @arr2 = "ac" "b" +# Output: false + +# Input: @arr1 = "ab" "cd" "e" +# @arr2 = "abcde" +# Output: true +# ------------------------------------ + + diff --git a/challenge-239/ulrich-rieke/cpp/ch-1.cpp b/challenge-239/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..cb66d87443 --- /dev/null +++ b/challenge-239/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,24 @@ +#include <iostream>
+#include <string>
+#include <regex>
+
+int main( ) {
+ std::string firstLine ;
+ std::string secondLine ;
+ std::cout << "Enter some strings, separated by blanks!\n" ;
+ std::getline( std::cin , firstLine ) ;
+ std::cout << "Enter some more strings, separated by blanks!\n" ;
+ std::getline( std::cin, secondLine ) ;
+ std::string replace( "" ) ;
+ std::string remove( "\\s+" ) ;
+ std::regex forRemoval( remove ) ;
+ std::string firstConcat ( std::regex_replace( firstLine , forRemoval ,
+ replace )) ;
+ std::string secondConcat( std::regex_replace( secondLine, forRemoval ,
+ replace ) ) ;
+ if ( firstConcat == secondConcat )
+ std::cout << "true\n" ;
+ else
+ std::cout << "false\n" ;
+ return 0 ;
+}
diff --git a/challenge-239/ulrich-rieke/cpp/ch-2.cpp b/challenge-239/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..91c98adf4b --- /dev/null +++ b/challenge-239/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,48 @@ +#include <vector>
+#include <string>
+#include <algorithm>
+#include <iostream>
+#include <set>
+
+std::set<char> toCharSet( std::string s ) {
+ std::set<char> charSet ( s.begin( ) , s.end( ) ) ;
+ return charSet ;
+}
+
+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 << "Please enter some strings, separated by blanks!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> allStrings( split( line , " " ) ) ;
+ std::cout << "Please enter an allowed string!\n" ;
+ std::string allowed ;
+ std::cin >> allowed ;
+ //we want to check whether the set of characters in allowed contains
+ //all the characters in the character set of a given word
+ //for that purpose, we convert the allowed string and all entered
+ //strings into set by calling the respective set constructor and then
+ //count the number of elements that are included in the allowed character
+ //set
+ std::set<char> allowedSet ( allowed.begin( ) , allowed.end( ) ) ;
+ std::vector<std::set<char>> allCharSets ;
+ for ( auto s : allStrings )
+ allCharSets.push_back( toCharSet( s ) ) ;
+ int count = std::count_if( allCharSets.begin( ) , allCharSets.end( ) ,
+ [allowedSet]( auto s ) { return std::includes( allowedSet.begin( ),
+ allowedSet.end( ) , s.begin( ) , s.end( ) ) ; } ) ;
+ std::cout << count << std::endl ;
+ return 0 ;
+}
diff --git a/challenge-239/ulrich-rieke/haskell/ch-1.hs b/challenge-239/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..822baf3247 --- /dev/null +++ b/challenge-239/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,12 @@ +module Challenge239
+ where
+
+main :: IO ( )
+main = do
+ putStrLn "Please enter some strings separated by blanks!"
+ firstStrings <- getLine
+ putStrLn "Enter some more strings separated by blanks!"
+ secondStrings <- getLine
+ let firstWord = foldl1 ( ++ ) $ words firstStrings
+ secondWord = foldl1 ( ++ ) $ words secondStrings
+ if firstWord == secondWord then print "true" else print "false"
diff --git a/challenge-239/ulrich-rieke/haskell/ch-2.hs b/challenge-239/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..3bd64f2f0a --- /dev/null +++ b/challenge-239/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,20 @@ +module Challenge239_2
+ where
+import qualified Data.Set as S
+
+isConsistent :: String -> String -> Bool
+isConsistent str allowed = all (\c -> elem c allowed ) str
+
+solution :: String -> String -> Int
+solution input allowed = length $ filter (\s -> isConsistent s allowed ) $
+ words input
+
+main :: IO ( )
+main = do
+ putStrLn "Please enter some strings, separated by blanks!"
+ strings <- getLine
+ putStrLn "Enter an allowed word!"
+ allowed <- getLine
+ --consider only unique characters in allowed
+ let set_allowed = S.toList $ S.fromList allowed
+ print $ solution strings set_allowed
diff --git a/challenge-239/ulrich-rieke/perl/ch-1.pl b/challenge-239/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..c4d86cedc0 --- /dev/null +++ b/challenge-239/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+say "Enter some strings, separated by blanks!" ;
+my $firstLine = <STDIN> ;
+chomp $firstLine ;
+say "Enter some more strings, separated by blanks!" ;
+my $secondLine = <STDIN> ;
+chomp $secondLine ;
+$firstLine =~ s/\s+//g ;
+$secondLine =~ s/\s+//g ;
+if ( $firstLine eq $secondLine ) {
+ say "true" ;
+}
+else {
+ say "false" ;
+}
diff --git a/challenge-239/ulrich-rieke/perl/ch-2.pl b/challenge-239/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..381e71f50b --- /dev/null +++ b/challenge-239/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( all ) ;
+
+#check whether all letters in a string are contained in a letter hash
+sub myCondition {
+ my $str = shift ;
+ my $letterHash = shift ;
+ return all { exists( $letterHash->{$_} ) } split( // , $str ) ;
+}
+
+say "Enter some strings, separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @strings = split( /\s/ , $line ) ;
+say "Enter an allowed string!" ;
+my $allowed = <STDIN> ;
+chomp $allowed ;
+#enter all letters in $allowed into a letter hash
+my %letterHash ;
+for my $c( split( // , $allowed ) ) {
+ $letterHash{ $c }++ ;
+}
+#check which strings comply with myCondition
+my @consistent = grep { myCondition( $_ , \%letterHash ) } @strings ;
+say scalar( @consistent ) ;
diff --git a/challenge-239/ulrich-rieke/raku/ch-1.raku b/challenge-239/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..e312dd2c82 --- /dev/null +++ b/challenge-239/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,9 @@ +use v6 ;
+
+say "Enter some strings, separated by blanks!" ;
+my $firstLine = $*IN.get ;
+say "Enter some more strings, separated by blanks!" ;
+my $secondLine = $*IN.get ;
+$firstLine.subst-mutate( /\s+/ , '' , :g) ;
+$secondLine.subst-mutate( /\s+/ , '' , :g) ;
+say ( $firstLine eq $secondLine ) ;
diff --git a/challenge-239/ulrich-rieke/raku/ch-2.raku b/challenge-239/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..ac9059a73b --- /dev/null +++ b/challenge-239/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,17 @@ +use v6 ;
+
+sub myCondition( $aString is copy, $allowedSet ) {
+ my $letterSet = $aString.comb.Set ;
+#the condition is fulfilled if the letterSet is a subset of allowedSet
+#or is equal to it
+ return $letterSet (<=) $allowedSet ;
+}
+
+say "Enter some strings, separated by blanks!" ;
+my $line = $*IN.get ;
+my @strings = $line.words ;
+say "Enter an allowed string!" ;
+my $allowed = $*IN.get ;
+my $allowedSet = Set.new( $allowed.comb ) ;
+my @consistent = @strings.grep( { myCondition( $_ , $allowedSet ) } ) ;
+say @consistent.elems ;
diff --git a/challenge-239/ulrich-rieke/rust/ch-1.rs b/challenge-239/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..c06b183452 --- /dev/null +++ b/challenge-239/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,21 @@ +use std::io ; + +fn main() { + println!("Enter some words, separated by blanks!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let first_line : &str = &*inline ; + let first_words : Vec<&str> = first_line.split_whitespace( ).map( | s | + s.trim( ) ).collect( ) ; + println!("Enter some more words , separated by blanks!") ; + let mut another_line : String = String::new( ) ; + io::stdin( ).read_line( &mut another_line ).unwrap( ) ; + let second_line : &str = &*another_line ; + let second_words : Vec<&str> = second_line.split_whitespace( ).map( | s | + s.trim( ) ).collect( ) ; + let mut concat_1 : String = String::new( ) ; + first_words.iter( ).for_each( | s | concat_1.push_str( s ) ) ; + let mut concat_2 : String = String::new( ) ; + second_words.iter( ).for_each( | s | concat_2.push_str( s ) ) ; + println!("{}" , concat_1 == concat_2 ) ; +} diff --git a/challenge-239/ulrich-rieke/rust/ch-2.rs b/challenge-239/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..4d9c8cd600 --- /dev/null +++ b/challenge-239/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,22 @@ +use std::io ; +use std::collections::HashSet ; + +fn main() { + println!("Please enter some strings, separated by blanks!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = &*inline ; + let all_strings : Vec<&str> = entered_line.split_whitespace( ).map( + | s | s.trim( ) ).collect( ) ; + println!("Enter an allowed string!") ; + let mut stringline : String = String::new( ) ; + io::stdin( ).read_line( &mut stringline ).unwrap( ) ; + let allowed : &str = stringline.as_str( ).trim( ) ; + let mut allowed_chars : HashSet<char> = HashSet::new( ) ; + for c in allowed.chars( ) { + allowed_chars.insert( c ) ; + } + let ct : usize = all_strings.iter( ).filter( | &s | + s.chars( ).all( | l | allowed_chars.contains( & l ) ) ).count( ) ; + println!("{}" , ct ) ; +} diff --git a/stats/pwc-challenge-238.json b/stats/pwc-challenge-238.json new file mode 100644 index 0000000000..9aaf3f3e9f --- /dev/null +++ b/stats/pwc-challenge-238.json @@ -0,0 +1,711 @@ +{ + "series" : [ + { + "name" : "The Weekly Challenge - 238", + "colorByPoint" : 1, + "data" : [ + { + "y" : 5, + "name" : "Ali Moradi", + "drilldown" : "Ali Moradi" + }, + { + "y" : 2, |
