diff options
Diffstat (limited to 'challenge-250')
| -rwxr-xr-x | challenge-250/ulrich-rieke/cpp/ch-1.cpp | 39 | ||||
| -rwxr-xr-x | challenge-250/ulrich-rieke/cpp/ch-2.cpp | 43 | ||||
| -rwxr-xr-x | challenge-250/ulrich-rieke/haskell/ch-1.hs | 8 | ||||
| -rwxr-xr-x | challenge-250/ulrich-rieke/haskell/ch-2.hs | 15 | ||||
| -rwxr-xr-x | challenge-250/ulrich-rieke/perl/ch-1.pl | 22 | ||||
| -rwxr-xr-x | challenge-250/ulrich-rieke/perl/ch-2.pl | 25 | ||||
| -rwxr-xr-x | challenge-250/ulrich-rieke/raku/ch-1.raku | 17 | ||||
| -rwxr-xr-x | challenge-250/ulrich-rieke/raku/ch-2.raku | 17 | ||||
| -rwxr-xr-x | challenge-250/ulrich-rieke/rust/ch-1.rs | 23 | ||||
| -rwxr-xr-x | challenge-250/ulrich-rieke/rust/ch-2.rs | 23 |
10 files changed, 232 insertions, 0 deletions
diff --git a/challenge-250/ulrich-rieke/cpp/ch-1.cpp b/challenge-250/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..79e5d6ad1e --- /dev/null +++ b/challenge-250/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,39 @@ +#include <vector>
+#include <iostream>
+#include <algorithm>
+#include <string>
+
+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 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 ) ) ;
+ std::vector<int> selected ;
+ for ( int i = 0 ; i < numbers.size( ) ; i++ ) {
+ if ( i % 10 == numbers[ i ] )
+ selected.push_back( i ) ;
+ }
+ if ( selected.size( ) > 0 )
+ std::cout << *std::min_element( selected.begin( ) , selected.end( ) ) ;
+ else {
+ std::cout << -1 ;
+ }
+ std::cout << std::endl ;
+ return 0 ;
+}
diff --git a/challenge-250/ulrich-rieke/cpp/ch-2.cpp b/challenge-250/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..3366da7ecf --- /dev/null +++ b/challenge-250/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,43 @@ +#include <vector>
+#include <iostream>
+#include <string>
+#include <algorithm>
+#include <cctype>
+
+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 convert( const std::string & s ) {
+ if ( std::any_of( s.begin( ) , s.end( ) , []( auto c ){ return
+ std::isalpha( c ) ; } ) ) {
+ return s.length( ) ;
+ }
+ else {
+ return std::stoi( s ) ;
+ }
+}
+
+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::vector<int> nums ( allStrings.size( ) ) ;
+ std::transform( allStrings.begin( ) , allStrings.end( ) ,
+ nums.begin( ) , convert ) ;
+ std::cout << *std::max_element( nums.begin( ) , nums.end( )) <<
+ std::endl ;
+ return 0 ;
+}
+
+
diff --git a/challenge-250/ulrich-rieke/haskell/ch-1.hs b/challenge-250/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..5223b4abc7 --- /dev/null +++ b/challenge-250/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,8 @@ +module Challenge250
+ where
+
+solution :: [Int] -> Int
+solution list = if null selected then -1 else minimum selected
+ where
+ selected = map fst $ filter (\p -> fst p `mod` 10 == snd p ) $ zip [0..] list
+
diff --git a/challenge-250/ulrich-rieke/haskell/ch-2.hs b/challenge-250/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..d195d5a20d --- /dev/null +++ b/challenge-250/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,15 @@ +module Challenge250_2
+ where
+import Data.Char ( isLetter )
+
+convert :: String -> Int
+convert s = if any isLetter s then length s else read s
+
+solution :: String -> Int
+solution = maximum . map convert . words
+
+main :: IO ( )
+main = do
+ putStrLn "Please enter some strings, separated by blanks!"
+ strings <- getLine
+ print $ solution strings
diff --git a/challenge-250/ulrich-rieke/perl/ch-1.pl b/challenge-250/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..01465f3e36 --- /dev/null +++ b/challenge-250/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( min ) ;
+
+say "Enter some integers separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s/ , $line ) ;
+my @selected ;
+for my $pos ( 0..scalar( @numbers ) - 1 ) {
+ if ( $pos % 10 == $numbers[ $pos ] ) {
+ push @selected , $pos ;
+ }
+}
+if ( @selected ) {
+ say min( @selected ) ;
+}
+else {
+ say -1 ;
+}
diff --git a/challenge-250/ulrich-rieke/perl/ch-2.pl b/challenge-250/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..92b7af750e --- /dev/null +++ b/challenge-250/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( max ) ;
+
+sub convert {
+ my $string = shift ;
+ if ( $string =~ /\D/ ) {
+ return length $string ;
+ }
+ else {
+ return ($string + 0) ;
+ }
+}
+
+say "Enter some strings, separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @strings = split( /\s/ , $line ) ;
+my @converted ;
+for my $s ( @strings ) {
+ push @converted , convert( $s ) ;
+}
+say max( @converted ) ;
diff --git a/challenge-250/ulrich-rieke/raku/ch-1.raku b/challenge-250/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..7aae7c6b75 --- /dev/null +++ b/challenge-250/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,17 @@ +use v6 ;
+
+say "Enter some integers, separated by blanks!" ;
+my $line = $*IN.get ;
+my @numbers = $line.words.map( {.Int} ) ;
+my @selected ;
+for (0..@numbers.elems - 1 ) -> $pos {
+ if ( $pos % 10 == @numbers[ $pos ] ) {
+ @selected.push( $pos ) ;
+ }
+}
+if ( @selected ) {
+ say @selected.min ;
+}
+else {
+ say "-1" ;
+}
diff --git a/challenge-250/ulrich-rieke/raku/ch-2.raku b/challenge-250/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..2206682cef --- /dev/null +++ b/challenge-250/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,17 @@ +use v6 ;
+
+sub convert( $aString ) {
+ if ( $aString ~~ /\D/ ) {
+ return $aString.chars ;
+ }
+ else {
+ return $aString.Int ;
+ }
+}
+
+say "Enter some strings, separated by blanks!" ;
+my $line = $*IN.get ;
+my @strings = $line.words ;
+my @converted ;
+@strings.map( { @converted.push( convert( $_ ) ) } ) ;
+say @converted.max ;
diff --git a/challenge-250/ulrich-rieke/rust/ch-1.rs b/challenge-250/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..7d8d5a7a31 --- /dev/null +++ b/challenge-250/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,23 @@ +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 entered_line : &str = &*inline ; + let numbers : Vec<i32> = entered_line.split_whitespace( ).map( | s | + s.trim( ).parse::<i32>( ).unwrap( ) ).collect( ) ; + let mut selected : Vec<usize> = Vec::new( ) ; + let len = numbers.len( ) ; + for i in 0..len { + if i % 10 == numbers[ i ] as usize { + selected.push( i ) ; + } + } + if selected.len( ) > 0 { + println!("{}" , selected.iter( ).min( ).unwrap( ) ) ; + } + else { + println!("-1") ; + } +} diff --git a/challenge-250/ulrich-rieke/rust/ch-2.rs b/challenge-250/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..2e96e6eda3 --- /dev/null +++ b/challenge-250/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,23 @@ +use std::io ; + +fn convert( term : &&str ) -> usize { + if term.chars( ).all( | d | d.is_digit( 10 )) { + term.parse::<usize>( ).unwrap( ) + } + else { + term.chars( ).count( ) + } +} + +fn main() { + println!("Please enter some strings , separated by words!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = &*inline ; + let terms : Vec<&str> = entered_line.split_whitespace( ).map( | s | + s.trim( ) ).collect( ) ; + let mut converted : Vec<usize> = Vec::new( ) ; + terms.iter( ).map( | w | convert( &w ) ).for_each( | d | + converted.push( d ) ) ; + println!("{}" , converted.iter( ).max( ).unwrap( ) ) ; +} |
