aboutsummaryrefslogtreecommitdiff
path: root/challenge-279
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-279')
-rwxr-xr-xchallenge-279/ulrich-rieke/cpp/ch-1.cpp38
-rwxr-xr-xchallenge-279/ulrich-rieke/cpp/ch-2.cpp14
-rwxr-xr-xchallenge-279/ulrich-rieke/haskell/ch-1.hs16
-rwxr-xr-xchallenge-279/ulrich-rieke/haskell/ch-2.hs12
-rwxr-xr-xchallenge-279/ulrich-rieke/perl/ch-1.pl17
-rwxr-xr-xchallenge-279/ulrich-rieke/perl/ch-2.pl18
-rwxr-xr-xchallenge-279/ulrich-rieke/raku/ch-1.raku11
-rwxr-xr-xchallenge-279/ulrich-rieke/raku/ch-2.raku6
-rwxr-xr-xchallenge-279/ulrich-rieke/rust/ch-1.rs33
-rwxr-xr-xchallenge-279/ulrich-rieke/rust/ch-2.rs18
10 files changed, 183 insertions, 0 deletions
diff --git a/challenge-279/ulrich-rieke/cpp/ch-1.cpp b/challenge-279/ulrich-rieke/cpp/ch-1.cpp
new file mode 100755
index 0000000000..8d6d6444c8
--- /dev/null
+++ b/challenge-279/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,38 @@
+#include <iostream>
+#include <string>
+#include <algorithm>
+#include <utility>
+#include <sstream>
+#include <vector>
+
+std::vector<std::string> tokenize( const std::string & text , char delimiter ) {
+ std::istringstream allTokens { text } ;
+ std::vector<std::string> tokens ;
+ std::string tok ;
+ while ( std::getline( allTokens , tok , delimiter ) ) {
+ tokens.push_back( tok ) ;
+ }
+ return tokens ;
+}
+
+int main( ) {
+ std::cout << "Enter some letters, separated by blanks!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> letterstrings { tokenize( line , ' ' ) } ;
+ std::cout << "Enter some weights, separated by blanks!\n" ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> weightstrings { tokenize( line , ' ' ) } ;
+ std::vector<std::pair<char , int>> allPairs ;
+ for ( int i = 0 ; i < letterstrings.size( ) ; i++ ) {
+ allPairs.push_back( std::make_pair( letterstrings[i].front( ) , std::stoi(
+ weightstrings[i].substr( 0 , 1 ) ) ) ) ;
+ }
+ std::sort( allPairs.begin( ) , allPairs.end( ) , []( const auto & p1 , const auto & p2) {
+ return p1.second < p2.second ; } ) ;
+ for ( auto p : allPairs )
+ std::cout << p.first ;
+ std::cout << '\n' ;
+ return 0 ;
+}
+
diff --git a/challenge-279/ulrich-rieke/cpp/ch-2.cpp b/challenge-279/ulrich-rieke/cpp/ch-2.cpp
new file mode 100755
index 0000000000..84455bf78a
--- /dev/null
+++ b/challenge-279/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,14 @@
+#include <string>
+#include <algorithm>
+#include <iostream>
+
+int main( ) {
+ std::cout << "Enter a string!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::string vowels {"aeiouAEIOU"} ;
+ std::cout << std::boolalpha << (std::count_if( line.begin( ) , line.end( ),
+ [vowels]( char c ) { return vowels.find( c ) != std::string::npos ;
+ } ) % 2 == 0 ) << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-279/ulrich-rieke/haskell/ch-1.hs b/challenge-279/ulrich-rieke/haskell/ch-1.hs
new file mode 100755
index 0000000000..eab77a6aa0
--- /dev/null
+++ b/challenge-279/ulrich-rieke/haskell/ch-1.hs
@@ -0,0 +1,16 @@
+module Challenge279
+ where
+import Data.Char ( digitToInt )
+import Data.List ( sortOn )
+
+solution :: String -> String -> String
+solution letters weights = filter (\c -> c /= ' ' ) $ unwords $ map fst $ sortOn snd $ zip
+ ( words letters ) ( map (\w -> digitToInt $ head w ) $ words weights )
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some letters separated by blanks!"
+ letterline <- getLine
+ putStrLn "Enter some weights separated by blanks!"
+ weightline <- getLine
+ print $ solution letterline weightline
diff --git a/challenge-279/ulrich-rieke/haskell/ch-2.hs b/challenge-279/ulrich-rieke/haskell/ch-2.hs
new file mode 100755
index 0000000000..8f04f999fe
--- /dev/null
+++ b/challenge-279/ulrich-rieke/haskell/ch-2.hs
@@ -0,0 +1,12 @@
+module Challenge279_2
+ where
+
+solution :: String -> Bool
+solution str = ( length $ filter (\c -> elem c "aeiouAEIOU" ) str ) `mod` 2
+ == 0
+
+main :: IO ( )
+main = do
+ putStrLn "Enter a string!"
+ line <- getLine
+ print $ solution line
diff --git a/challenge-279/ulrich-rieke/perl/ch-1.pl b/challenge-279/ulrich-rieke/perl/ch-1.pl
new file mode 100755
index 0000000000..6c55640fec
--- /dev/null
+++ b/challenge-279/ulrich-rieke/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( zip ) ;
+
+say "Enter some letters , separated by blanks!" ;
+my $letters = <STDIN> ;
+chomp $letters ;
+my @letters = split( /\s+/ , $letters ) ;
+say "Enter some weights , separated by blanks!" ;
+my $weights = <STDIN> ;
+chomp $weights ;
+my @weights = split( /\s+/ , $weights ) ;
+my @zipped = zip( \@letters , \@weights ) ;
+my @sorted = sort { $a->[1] <=> $b->[1] } @zipped ;
+say join( '' , map { $_->[0] } @sorted ) ;
diff --git a/challenge-279/ulrich-rieke/perl/ch-2.pl b/challenge-279/ulrich-rieke/perl/ch-2.pl
new file mode 100755
index 0000000000..0d0cfa31b4
--- /dev/null
+++ b/challenge-279/ulrich-rieke/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+#the task amounts to verifying whether the number of vowels in the string
+#is even or odd
+say "Enter a string!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my $vowels = "aeiouAEIOU" ;
+if ( scalar( grep { index( $vowels , $_ ) != -1 } split( // , $line ) )
+ % 2 == 0 ) {
+ say "true" ;
+}
+else {
+ say "false" ;
+}
diff --git a/challenge-279/ulrich-rieke/raku/ch-1.raku b/challenge-279/ulrich-rieke/raku/ch-1.raku
new file mode 100755
index 0000000000..99104226cd
--- /dev/null
+++ b/challenge-279/ulrich-rieke/raku/ch-1.raku
@@ -0,0 +1,11 @@
+use v6 ;
+
+say "Enter some letters , separated by blanks!" ;
+my $letters = $*IN.get ;
+say "Enter some weights, separated by blanks!" ;
+my $weights = $*IN.get ;
+my @letters_in = $letters.words ;
+my @weights_in = $weights.words.map( {.Int} ) ;
+my @pairs = @letters_in Z, @weights_in ;
+my @sorted = @pairs.sort( *.[1] ).map( {$_[0]} ) ;
+say @sorted.join ;
diff --git a/challenge-279/ulrich-rieke/raku/ch-2.raku b/challenge-279/ulrich-rieke/raku/ch-2.raku
new file mode 100755
index 0000000000..e7df535f8f
--- /dev/null
+++ b/challenge-279/ulrich-rieke/raku/ch-2.raku
@@ -0,0 +1,6 @@
+use v6 ;
+
+say "Enter a string!" ;
+my $line = $*IN.get ;
+my @vowels = "aeiouAEIOU".comb ;
+say $line.comb.grep( {$_ (elem) @vowels} ).elems %% 2 ;
diff --git a/challenge-279/ulrich-rieke/rust/ch-1.rs b/challenge-279/ulrich-rieke/rust/ch-1.rs
new file mode 100755
index 0000000000..d0e0429eea
--- /dev/null
+++ b/challenge-279/ulrich-rieke/rust/ch-1.rs
@@ -0,0 +1,33 @@
+use std::io ;
+
+fn main() {
+ println!("Enter some letters!");
+ let mut letterline : String = String::new( ) ;
+ io::stdin( ).read_line( &mut letterline ).unwrap( ) ;
+ let letterstr : &str = letterline.as_str( ).trim( ) ;
+ println!("Enter some weights!") ;
+ let mut weightline : String = String::new( ) ;
+ io::stdin( ).read_line( &mut weightline ).unwrap( ) ;
+ let weightstr : &str = weightline.as_str( ).trim( ) ;
+ let weights : Vec<usize> = weightstr.split_whitespace( ).map( | s |
+ s.parse::<usize>( ).unwrap( )).collect( ) ;
+ let mut letters_entered : String = String::new( ) ;
+ for c in letterstr.chars( ) {
+ if c != ' ' {
+ letters_entered.push( c ) ;
+ }
+ }
+ let single_letters = letters_entered.as_str( ) ;
+ let mut pairs : Vec<(char,usize)> = single_letters.chars( ).zip( weights.into_iter( )).
+ collect( ) ;
+ let pair_slice = pairs.as_mut_slice( ) ;
+ pair_slice.sort_by( | a , b | a.1.cmp( &b.1 )) ;
+ let sorted_pairs : Vec<(char, usize)> = pair_slice.to_vec( ) ;
+ let final_chars : Vec<char> = sorted_pairs.into_iter( ).map( | p | p.0 ).
+ collect( ) ;
+ let mut solution : String = String::new( ) ;
+ for c in final_chars {
+ solution.push( c ) ;
+ }
+ println!("{:?}" , solution ) ;
+}
diff --git a/challenge-279/ulrich-rieke/rust/ch-2.rs b/challenge-279/ulrich-rieke/rust/ch-2.rs
new file mode 100755
index 0000000000..92dcc015f4
--- /dev/null
+++ b/challenge-279/ulrich-rieke/rust/ch-2.rs
@@ -0,0 +1,18 @@
+use std::io ;
+
+fn is_vowel( c : char ) -> bool {
+ let vowels : &str = "aeiouAEIOU" ;
+ vowels.find( c ).is_some( )
+}
+
+//the task amounts to verifying whether the number of vowels in the string
+//is even or odd
+fn main() {
+ println!("Enter a string!");
+ let mut inline : String = String::new( ) ;
+ io::stdin( ).read_line( &mut inline ).unwrap( ) ;
+ let entered_line : &str = inline.as_str( ).trim( ) ;
+ let result : bool = entered_line.chars( ).filter( | &c | is_vowel( c ))
+ .count( ) % 2 == 0 ;
+ println!("{}" , result ) ;
+}