aboutsummaryrefslogtreecommitdiff
path: root/challenge-171/ulrich-rieke/cpp
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-06-29 23:31:11 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-06-29 23:31:11 +0100
commit7755a024f5e0ed7581cce5bdaf7d1156e83fe076 (patch)
tree12af4c1ef99749dd620f12084b05176fbf68ec0a /challenge-171/ulrich-rieke/cpp
parent48b64c2eb83bf27099b00d37e78a1308f8e3921d (diff)
downloadperlweeklychallenge-club-7755a024f5e0ed7581cce5bdaf7d1156e83fe076.tar.gz
perlweeklychallenge-club-7755a024f5e0ed7581cce5bdaf7d1156e83fe076.tar.bz2
perlweeklychallenge-club-7755a024f5e0ed7581cce5bdaf7d1156e83fe076.zip
- Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-171/ulrich-rieke/cpp')
-rw-r--r--challenge-171/ulrich-rieke/cpp/ch-1.cpp32
-rw-r--r--challenge-171/ulrich-rieke/cpp/ch-2.cpp19
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-171/ulrich-rieke/cpp/ch-1.cpp b/challenge-171/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..64182ec9a4
--- /dev/null
+++ b/challenge-171/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,32 @@
+#include <iostream>
+#include <vector>
+#include <numeric>
+
+std::vector<int> findDivisors( int n ) {
+ std::vector<int> divisors ;
+ for ( int i = 1 ; i < (n / 2 ) + 1 ; i++ ) {
+ if ( n % i == 0 )
+ divisors.push_back( i ) ;
+ }
+ return divisors ;
+}
+
+bool isAbundant( int n ) {
+ std::vector<int> divisors = findDivisors( n ) ;
+ int sum = std::accumulate( divisors.begin( ) , divisors.end( ) , 0 ) ;
+ return sum > n ;
+}
+
+int main( ) {
+ std::vector<int> oddAbundant ;
+ int current = 3 ;
+ while ( oddAbundant.size( ) != 20 ) {
+ if ( isAbundant( current ) )
+ oddAbundant.push_back( current ) ;
+ current += 2 ;
+ }
+ for ( int n : oddAbundant )
+ std::cout << n << ' ' ;
+ std::cout << std::endl ;
+ return 0 ;
+}
diff --git a/challenge-171/ulrich-rieke/cpp/ch-2.cpp b/challenge-171/ulrich-rieke/cpp/ch-2.cpp
new file mode 100644
index 0000000000..d7bdcc363e
--- /dev/null
+++ b/challenge-171/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,19 @@
+#include <iostream>
+#include <cmath>
+
+int func1( int n ) {
+ return 5 * n ;
+}
+
+double func2 ( int m ) {
+ return std::sqrt( static_cast<double>( m ) ) ;
+}
+
+double compose( int n ) {
+ return func2( func1( n ) ) ;
+}
+
+int main( ) {
+ std::cout << compose( 6 ) << '\n' ;
+ return 0 ;
+}