aboutsummaryrefslogtreecommitdiff
path: root/challenge-108
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-108')
-rw-r--r--challenge-108/ulrich-rieke/cpp/ch-1.cpp10
-rw-r--r--challenge-108/ulrich-rieke/cpp/ch-2.cpp26
-rw-r--r--challenge-108/ulrich-rieke/perl/ch-1.pl8
-rw-r--r--challenge-108/ulrich-rieke/perl/ch-2.pl30
-rw-r--r--challenge-108/ulrich-rieke/raku/ch-1.raku4
-rw-r--r--challenge-108/ulrich-rieke/raku/ch-2.raku30
6 files changed, 108 insertions, 0 deletions
diff --git a/challenge-108/ulrich-rieke/cpp/ch-1.cpp b/challenge-108/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..e8d0b8b2fe
--- /dev/null
+++ b/challenge-108/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,10 @@
+#include <vector>
+#include <iostream>
+#include <string>
+
+int main( ) {
+ std::vector<std::string> cities { "Amsterdam" , "Berlin" , "Moscow" } ;
+ std::cout << "The vector cities is located at " << &cities << " !\n" ;
+ std::cout << "Its memory size is " << sizeof( cities ) << " !\n" ;
+ return 0 ;
+}
diff --git a/challenge-108/ulrich-rieke/cpp/ch-2.cpp b/challenge-108/ulrich-rieke/cpp/ch-2.cpp
new file mode 100644
index 0000000000..5d39d4793d
--- /dev/null
+++ b/challenge-108/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,26 @@
+#include <vector>
+#include <iostream>
+
+int main( ) {
+ std::vector<int> bellnumbers { 1 } ;
+ std::vector<int> currentRow ;
+ std::vector<int> previousRow { 1 } ;
+ while ( bellnumbers.size( ) < 10 ) {
+ currentRow.push_back( previousRow.back( )) ;
+ int currentIndex = 0 ;
+ while ( currentRow.size( ) < ( previousRow.size( ) + 1 ) ) {
+ currentIndex++ ;
+ currentRow.push_back( currentRow[ currentIndex - 1 ] +
+ previousRow[ currentIndex - 1 ] ) ;
+ }
+ bellnumbers.push_back( *(currentRow.begin( ) ) ) ;
+ previousRow = currentRow ;
+ currentRow.clear( ) ;
+ }
+ std::cout << "These are the first 10 Bell numbers:\n" ;
+ for ( int i = 1 ; i < 10 ; i++ ) {
+ std::cout << " " << i << " : " << bellnumbers[ i - 1 ] << '\n' ;
+ }
+ std::cout << 10 << " : " << bellnumbers[9] << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-108/ulrich-rieke/perl/ch-1.pl b/challenge-108/ulrich-rieke/perl/ch-1.pl
new file mode 100644
index 0000000000..4ee08f700b
--- /dev/null
+++ b/challenge-108/ulrich-rieke/perl/ch-1.pl
@@ -0,0 +1,8 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+my @cities = ("Berlin", "Amsterdam", "Moscow") ;
+my $addr = \@cities ;
+say "The address of \@cities is $addr!" ;
diff --git a/challenge-108/ulrich-rieke/perl/ch-2.pl b/challenge-108/ulrich-rieke/perl/ch-2.pl
new file mode 100644
index 0000000000..766ac2cc56
--- /dev/null
+++ b/challenge-108/ulrich-rieke/perl/ch-2.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+my @bellnumbers = ( 1 ) ;
+my @current_row ; #for the row we collect numbers in
+my @previous_row = ( 1 ) ; #the last row we created
+while ( scalar @bellnumbers < 10 ) {
+ push @current_row , $previous_row[ -1 ] ;
+ my $current_index = 0 ;
+ do {
+ $current_index++ ;
+ $current_row[ $current_index] = $current_row[ $current_index - 1]
+ + $previous_row[ $current_index - 1] ;
+ } while ( scalar @current_row < scalar @previous_row + 1 ) ;
+ push @bellnumbers , $current_row[ 0 ] ;
+ @previous_row = @current_row ;
+ @current_row = ( ) ;
+}
+say "These are the first 10 Bell numbers!" ;
+for my $i (1 .. 10 ) {
+ if ( $i < 10 ) {
+ print " $i : " ;
+ }
+ else {
+ print "$i : " ;
+ }
+ say $bellnumbers[ $i - 1 ] ;
+}
diff --git a/challenge-108/ulrich-rieke/raku/ch-1.raku b/challenge-108/ulrich-rieke/raku/ch-1.raku
new file mode 100644
index 0000000000..385350c38d
--- /dev/null
+++ b/challenge-108/ulrich-rieke/raku/ch-1.raku
@@ -0,0 +1,4 @@
+use v6 ;
+
+my @cities = ("Berlin", "Amsterdam", "Moscow" , "New York") ;
+say "The address of \@cities is located at " ~ @cities.WHERE ~ "!" ;
diff --git a/challenge-108/ulrich-rieke/raku/ch-2.raku b/challenge-108/ulrich-rieke/raku/ch-2.raku
new file mode 100644
index 0000000000..91441f2d1b
--- /dev/null
+++ b/challenge-108/ulrich-rieke/raku/ch-2.raku
@@ -0,0 +1,30 @@
+use v6 ;
+
+#this task calculates the first 10 Bell numbers applying the triangle
+#rule that carries his name
+
+my @bellnumbers = ( 1 ) ;
+my @current_row ;#where we collect the numbers in the row
+my @previous_row = ( 1 ) ;
+while (@bellnumbers.elems < 10) {
+ @current_row.push( @previous_row[ *-1 ] ) ;
+ my $current_index = 0 ;
+ repeat {
+ $current_index++ ;
+ @current_row[ $current_index] = @current_row[ $current_index - 1 ]
+ + @previous_row[ $current_index - 1 ] ;
+ } until ( @current_row.elems == @previous_row.elems + 1 ) ;
+ @bellnumbers.push( @current_row[ 0 ] ) ;
+ @previous_row = @current_row ;
+ @current_row = ( ) ;
+}
+say "These are the first 10 Bell numbers!" ;
+for ( 1 .. 10 ) -> $i {
+ if ( $i < 10 ) {
+ print " $i : " ;
+ }
+ else {
+ print "$i : " ;
+ }
+ say "@bellnumbers[ $i - 1 ]" ;
+}