diff options
37 files changed, 1124 insertions, 535 deletions
diff --git a/challenge-342/eric-cheung/python/ch-1.py b/challenge-342/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..5f4b5baaec --- /dev/null +++ b/challenge-342/eric-cheung/python/ch-1.py @@ -0,0 +1,19 @@ +
+## strInput = "a0b1c2" ## Example 1
+## strInput = "abc12" ## Example 2
+## strInput = "0a2b1c3" ## Example 3
+## strInput = "1a23" ## Example 4
+strInput = "ab123" ## Example 5
+
+arrChar = list(strInput)
+arrAlpha = sorted([charLoop for charLoop in arrChar if charLoop.isalpha()])
+arrNum = sorted([charLoop for charLoop in arrChar if charLoop.isdigit()])
+
+if abs(len(arrAlpha) - len(arrNum)) > 1:
+ print ("")
+elif len(arrAlpha) == len(arrNum):
+ print ("".join([numLoop + charLoop for numLoop, charLoop in zip(arrNum, arrAlpha)]))
+elif len(arrAlpha) < len(arrNum):
+ print ("".join([numLoop + charLoop for numLoop, charLoop in zip(arrNum[:-1], arrAlpha)]) + arrNum[-1])
+else:
+ print ("".join([charLoop + numLoop for charLoop, numLoop in zip(arrAlpha[:-1], arrNum)]) + arrAlpha[-1])
diff --git a/challenge-342/eric-cheung/python/ch-2.py b/challenge-342/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..877906d0bb --- /dev/null +++ b/challenge-342/eric-cheung/python/ch-2.py @@ -0,0 +1,13 @@ +
+def GetStrScore (strInput_Left, strInput_Right):
+ return strInput_Left.count("0") + strInput_Right.count("1")
+
+## strInput = "0011" ## Example 1
+## strInput = "0000" ## Example 2
+## strInput = "1111" ## Example 3
+## strInput = "0101" ## Example 4
+strInput = "011101" ## Example 5
+
+arrOutput = [GetStrScore(strInput[:nIndx], strInput[nIndx:]) for nIndx in range(1, len(strInput))]
+
+print (max(arrOutput))
diff --git a/challenge-342/ulrich-rieke/cpp/ch-1.cpp b/challenge-342/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..6eea871df8 --- /dev/null +++ b/challenge-342/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,51 @@ +#include <iostream>
+#include <string>
+#include <algorithm>
+#include <vector>
+#include <cctype>
+#include <cstdlib>
+
+int main( ) {
+ std::cout << "Enter a word with lowercase English letters and digits only!\n" ;
+ std::string word ;
+ std::cin >> word ;
+ std::vector<char> letters , digits ;
+ for ( char c : word ) {
+ if ( std::isdigit( c ) )
+ digits.push_back( c ) ;
+ else
+ letters.push_back( c ) ;
+ }
+ int lettercount = static_cast<int>( letters.size( ) ) ;
+ int digitcount = static_cast<int>( digits.size( ) ) ;
+ if ( std::abs( lettercount - digitcount ) > 1 ) {
+ std::cout << "\"\"\n" ;
+ }
+ else {
+ std::sort( letters.begin( ) , letters.end( ) ) ;
+ std::sort( digits.begin( ) , digits.end( ) ) ;
+ std::string solution ;
+ if ( digitcount >= lettercount ) {
+ while ( digits.size( ) > 0 ) {
+ solution.push_back( *digits.begin( ) ) ;
+ digits.erase( digits.begin( ) ) ;
+ if ( letters.size( ) > 0 ) {
+ solution.push_back( *letters.begin( ) ) ;
+ letters.erase( letters.begin( ) ) ;
+ }
+ }
+ }
+ else {
+ while ( letters.size( ) > 0 ) {
+ solution.push_back( *letters.begin( ) ) ;
+ letters.erase( letters.begin( ) ) ;
+ if ( digits.size( ) > 0 ) {
+ solution.push_back( *digits.begin( ) ) ;
+ digits.erase( digits.begin( ) ) ;
+ }
+ }
+ }
+ std::cout << solution << '\n' ;
+ }
+ return 0 ;
+}
diff --git a/challenge-342/ulrich-rieke/cpp/ch-2.cpp b/challenge-342/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..dbd77b82e2 --- /dev/null +++ b/challenge-342/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,28 @@ +#include <iostream>
+#include <string>
+#include <algorithm>
+#include <vector>
+using namespace std::string_literals ;
+
+int main( ) {
+ std::cout << "Enter a string consisting of 0 and 1 only!\n" ;
+ std::string word ;
+ std::cin >> word ;
+ std::vector<int> subsums ;
+ int len = static_cast<int>( word.length( ) ) ;
+ for ( int i = 1 ; i < len - 1 ; i++ ) {
+ int zeroes = 0 ;
+ for ( int pos = 0 ; pos < i + 1 ; pos++ ) {
+ if ( word.substr( pos , 1 ) == "0"s )
+ zeroes++ ;
+ }
+ int ones = 0 ;
+ for ( int pos = i ; pos < len ; pos++ )
+ if ( word.substr( pos , 1 ) == "1"s )
+ ones++ ;
+ subsums.push_back( zeroes + ones ) ;
+ }
+ std::cout << *std::max_element( subsums.begin( ) , subsums.end( ) ) <<
+ '\n' ;
+ return 0 ;
+}
diff --git a/challenge-342/ulrich-rieke/haskell/ch-1.hs b/challenge-342/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..cdf3e5555c --- /dev/null +++ b/challenge-342/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,26 @@ +module Challenge342
+ where
+import Data.List ( sort )
+import Data.Char ( isDigit )
+
+separate :: String -> (String , String)
+separate str = ( sort $ filter isDigit str , sort $ filter ( not . isDigit ) str )
+
+solution :: String -> String
+solution str
+ |abs( letterlen - digitlen) > 1 = ""
+ |digitlen - letterlen == 1 = (foldl1 (++ ) $ map (\p -> [fst p] ++ [snd p] ) $ zip digits letters) ++
+ [last digits]
+ |digitlen == letterlen = foldl1 ( ++ ) $ map (\p -> [fst p] ++ [snd p]) $ zip digits letters
+ |letterlen - digitlen == 1 = (foldl1 (++) $ map (\p -> [fst p] ++ [snd p]) $ zip letters digits) ++
+ [last letters]
+ where
+ (digits , letters) = separate str
+ digitlen = length digits
+ letterlen = length letters
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a string with lowercase English letters and digits only!"
+ word <- getLine
+ print $ solution word
diff --git a/challenge-342/ulrich-rieke/haskell/ch-2.hs b/challenge-342/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..90e7f2d132 --- /dev/null +++ b/challenge-342/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,20 @@ +module Challenge342_2
+ where
+import Data.List( splitAt , findIndices )
+
+countChars :: String -> Char -> Int
+countChars str c = length $ findIndices( == c ) str
+
+solution :: String -> Int
+solution str =
+ let l = length str
+ splitPairs = [splitAt n str | n <- [1..l - 1]]
+ zerocounts = map ( (flip countChars '0' ) . fst ) splitPairs
+ onecounts = map ( (flip countChars '1' ) . snd ) splitPairs
+ in maximum $ zipWith ( + ) zerocounts onecounts
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a string consisting of 0 and 1 only!"
+ word <- getLine
+ print $ solution word
diff --git a/challenge-342/ulrich-rieke/perl/ch-1.pl b/challenge-342/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..8ae6889fdf --- /dev/null +++ b/challenge-342/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use POSIX ;
+say "Enter a string with lowercase English letters and digits only!" ;
+my $word = <STDIN> ;
+chomp $word ;
+my @letters ;
+my @digits ;
+for my $l ( split( // , $word ) ) {
+ if ( $l =~ /\d/ ) {
+ push( @digits , $l ) ;
+ }
+ else {
+ push( @letters , $l ) ;
+ }
+}
+my $lettercount = scalar( @letters ) ;
+my $digitcount = scalar( @digits ) ;
+if ( abs( $lettercount - $digitcount ) > 1 ) {
+ say "\"\"" ;
+}
+else {
+ my @sortedChars = sort @letters ;
+ my @sortedDigits = sort @digits ;
+ my @solution ;
+ if ( $digitcount >= $lettercount ) {
+ while ( @sortedDigits ) {
+ push( @solution , shift @sortedDigits ) ;
+ if ( @sortedChars ) {
+ push( @solution , shift @sortedChars ) ;
+ }
+ }
+ }
+ else {
+ while( @sortedChars ) {
+ push( @solution , shift @sortedChars ) ;
+ if ( @sortedDigits ) {
+ push( @solution , shift @sortedDigits ) ;
+ }
+ }
+ }
+ say join( '' , @solution ) ;
+}
+
+
+
diff --git a/challenge-342/ulrich-rieke/perl/ch-2.pl b/challenge-342/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..6b44419317 --- /dev/null +++ b/challenge-342/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( max ) ;
+
+say "Enter a string consisting of 0 and 1 only!" ;
+my $word = <STDIN> ;
+chomp $word ;
+my $len = length( $word ) ;
+my @subsums ;
+for my $pos( 1..$len - 1 ) {
+ my @left = split( // , substr( $word , 0 , $pos )) ;
+ my @right = split( // , substr( $word , $pos )) ;
+ my $zeroes = scalar( grep { $_ eq '0' } @left ) ;
+ my $ones = scalar( grep { $_ eq '1' } @right ) ;
+ push( @subsums , $zeroes + $ones ) ;
+}
+say max( @subsums ) ;
diff --git a/challenge-342/ulrich-rieke/python/ch-2.py b/challenge-342/ulrich-rieke/python/ch-2.py new file mode 100755 index 0000000000..0fbff6843c --- /dev/null +++ b/challenge-342/ulrich-rieke/python/ch-2.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3
+
+line = input("Enter a string consisting of 0 and 1 only!\n") ;
+ln = len( line ) ;
+subsums = [] ;
+for pos in range(1,ln):
+ firstpart = line[0:pos]
+ secondpart = line[pos:ln]
+ zeroes = firstpart.count( '0' )
+ ones = secondpart.count('1') ;
+ subsums.append( zeroes + ones )
+subsums.sort( )
+print(subsums[-1])
diff --git a/challenge-342/ulrich-rieke/raku/ch-1.raku b/challenge-342/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..06db5466f9 --- /dev/null +++ b/challenge-342/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,42 @@ +use v6 ;
+#if the difference of the number of letters and digits is greater than 1 the task
+#can't be solved. If the the number of digits is greater than or equal to the number
+#of letters we alternatingly take digits and letters from the sorted digits and letters,
+#otherwise vice versa
+say "Enter a string with lowercase English letters and digits only!" ;
+my $word = $*IN.get ;
+my @digits ;
+my @letters ;
+for $word.comb -> $l {
+ if ( $l ~~ /\d/ ) {
+ @digits.push( $l ) ;
+ }
+ else {
+ @letters.push( $l ) ;
+ }
+}
+if ( @digits.elems - @letters.elems).abs > 1 {
+ say "\"\"" ;
+}
+else {
+ @digits .= sort ;
+ @letters .= sort ;
+ my @solution ;
+ if ( @digits.elems >= @letters.elems ) {
+ while ( @digits ) {
+ @solution.push( @digits.shift ) ;
+ if ( @letters.elems > 0 ) {
+ @solution.push( @letters.shift ) ;
+ }
+ }
+ }
+ else {
+ while ( @letters ) {
+ @solution.push( @letters.shift ) ;
+ if ( @digits.elems > 0 ) {
+ @solution.push( @digits.shift ) ;
+ }
+ }
+ }
+ say @solution.join('') ;
+}
diff --git a/challenge-342/ulrich-rieke/raku/ch-2.raku b/challenge-342/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..dc81432864 --- /dev/null +++ b/challenge-342/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,14 @@ +use v6 ;
+
+say "Enter a string consisting of 0 and 1 only!" ;
+my $word = $*IN.get ;
+my $len = $word.chars ;
+my @subsums ;
+for (1..$len - 1 ) -> $pos {
+ my @left = $word.substr( 0 , $pos ).comb ;
+ my $zeroes = @left.grep( {$_ eq '0'} ).elems ;
+ my @right = $word.substr( $pos ).comb ;
+ my $ones = @right.grep( {$_ eq '1'} ).elems ;
+ @subsums.push( $zeroes + $ones ) ;
+}
+say @subsums.max ;
diff --git a/challenge-342/ulrich-rieke/rust/ch-1.rs b/challenge-342/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..2880080bf0 --- /dev/null +++ b/challenge-342/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,45 @@ +use std::io ; + +fn main() { + println!("Enter a string of lowercase English letters and digits only!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let input : &str = inline.trim( ) ; + //count the number of letters and of digits. If these differ by more than + //one we return an empty string , otherwise we sort letters and digits. If + //there are more digits than letters or both are equal we start with the + //smallest digit else with the smallest letter + let len : usize = input.chars( ).count( ) ; + let lettercount : usize = input.chars( ).filter( |c| c.is_ascii_lowercase( )). + count( ) ; + let digitcount : usize = len - lettercount ; + if (lettercount as i32).abs_diff( digitcount as i32 ) > 1 { + println!("\"\"") ; + } + else { + let mut letters : Vec<char> = Vec::new( ) ; + let mut digits : Vec<char> = Vec::new( ) ; + input.chars( ).filter( |c| c.is_ascii_lowercase( )).for_each( |d| letters.push( d )) ; + input.chars( ).filter( |c| (*c).is_digit(10 )).for_each( |d| digits.push( d ) ) ; + letters.sort( ) ; + digits.sort( ) ; + let mut solution : String = String::new( ) ; + if digitcount >= lettercount { + while digits.len( ) > 0 { + solution.push( digits.remove( 0 )) ; + if letters.len( ) > 0 { + solution.push( letters.remove( 0 ) ) ; + } + } + } + else { + while letters.len( ) > 0 { + solution.push( letters.remove( 0 ) ) ; + if digits.len( ) > 0 { + solution.push( digits.remove( 0 ) ) ; + } + } + } + println!("{:?}" , solution ) ; + } +} diff --git a/challenge-342/ulrich-rieke/rust/ch-2.rs b/challenge-342/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..fd1b687da3 --- /dev/null +++ b/challenge-342/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,18 @@ +use std::io ; + +fn main() { + println!("Enter a string consisting of 1 and 0 only!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let input : &str = inline.trim( ) ; + let len : usize = input.chars( ).count( ) ; + let mut splitscores : Vec<usize> = Vec::new( ) ; + for pos in 1..len { + let zeroes : usize = input.chars( ).take( pos ).filter( |c| + *c == '0' ).count( ) ; + let ones : usize = input.chars( ).skip( pos ).filter( |c| + *c == '1').count( ) ; + splitscores.push( zeroes + ones ) ; + } + println!("{}" , splitscores.into_iter( ).max( ).unwrap( ) ) ; +} diff --git a/stats/pwc-challenge-341.json b/stats/pwc-challenge-341.json new file mode 100644 index 0000000000..191b92aa7c --- /dev/null +++ b/stats/pwc-challenge-341.json @@ -0,0 +1,664 @@ +{ + "chart" : { + "type" : "column" + }, + "drilldown" : { + "series" : [ + { + "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", + 1 + ] + ], + "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 + ] + ], + "id" : "Kjetil Skotheim", + "name" : "Kjetil Skotheim" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Lubos Kolouch", + "name" : "Lubos Kolouch" + }, + { + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 10 + ] + ], + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Mariano Spadaccini", + "name" : "Mariano Spadaccini" + }, + { + "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", + 1 + ] + ], + "id" : "Mohammad Sajid Anwar", + "name" : "Mohammad Sajid Anwar" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Nicolas Mendoza", + "name" : "Nicolas Mendoza" + }, + { + "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" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Roger Bell_West", + "name" : "Roger Bell_West" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Ryan Thompson", + "name" : "Ryan Thompson" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Simon Green", + "name" : "Simon Green" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Thomas Kohler", + "name" : "Thomas Kohler" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Torgny Lyon", + "name" : "Torgny Lyon" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Vinod Kumar K", + "name" : "Vinod Kumar K" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "W. Luis Mochan", + |
