aboutsummaryrefslogtreecommitdiff
path: root/challenge-085
diff options
context:
space:
mode:
authorPhilip Hood <hood@panix.com>2020-11-02 12:42:47 -0500
committerPhilip Hood <hood@panix.com>2020-11-02 12:42:47 -0500
commitb88d0018e8e7ec33fb5c774507ea440acfd9b3e7 (patch)
tree2a4b442cb2c778a09b3894e0f2df19530049b41f /challenge-085
parent6c90a1a2a3dbac83404fd113a482105ce7a82358 (diff)
downloadperlweeklychallenge-club-b88d0018e8e7ec33fb5c774507ea440acfd9b3e7.tar.gz
perlweeklychallenge-club-b88d0018e8e7ec33fb5c774507ea440acfd9b3e7.tar.bz2
perlweeklychallenge-club-b88d0018e8e7ec33fb5c774507ea440acfd9b3e7.zip
c++ solutions for ch's 1 & 2 in c++ ...
Diffstat (limited to 'challenge-085')
-rw-r--r--challenge-085/pkmnx/c++/ch-1/Makefile4
-rw-r--r--challenge-085/pkmnx/c++/ch-1/ch-1.cpp64
-rw-r--r--challenge-085/pkmnx/c++/ch-1/sample.input4
-rw-r--r--challenge-085/pkmnx/c++/ch-2/Makefile4
-rw-r--r--challenge-085/pkmnx/c++/ch-2/ch-2.cpp47
5 files changed, 123 insertions, 0 deletions
diff --git a/challenge-085/pkmnx/c++/ch-1/Makefile b/challenge-085/pkmnx/c++/ch-1/Makefile
new file mode 100644
index 0000000000..5ad1c62a72
--- /dev/null
+++ b/challenge-085/pkmnx/c++/ch-1/Makefile
@@ -0,0 +1,4 @@
+all:
+ g++ -o ch-1 ch-1.cpp -Wall -pedantic -ansi
+clean:
+ rm *.o
diff --git a/challenge-085/pkmnx/c++/ch-1/ch-1.cpp b/challenge-085/pkmnx/c++/ch-1/ch-1.cpp
new file mode 100644
index 0000000000..d87629395f
--- /dev/null
+++ b/challenge-085/pkmnx/c++/ch-1/ch-1.cpp
@@ -0,0 +1,64 @@
+#include <vector>
+#include <map>
+#include <iostream>
+#include <bits/stdc++.h>
+
+using namespace std;
+
+void permute( vector<double> v ) {
+
+ sort( v.begin(), v.end() );
+
+ map<double, map <double, map <double, bool> > > m;
+
+ do {
+
+ double a = v[0];
+ double b = v[1];
+ double c = v[2];
+
+ if ( m[ a ][ b ][ c ] ) {
+ // nothing ...
+
+ } else {
+
+ m[ a ][ b ][ c ] = true;
+
+ double sum = a + b + c;
+ if ( sum > 1 && sum < 2 ) {
+ cout << "Output: 1 as 1 < " << a << " + " << b << " + " << c << " < 2" << endl;
+ exit(0);
+ }
+
+ }
+
+ } while ( next_permutation( v.begin(), v.end() ) );
+
+}
+
+int main() {
+
+ vector<double> v;
+
+ double x;
+ while ( cin >> x ) { v.push_back(x); }
+
+ if ( v.size() > 0 ) {
+
+ cout << "Input: @R = (" << v[0];
+
+ for ( std::vector<double>::size_type i = 1; i < v.size(); i++ ) {
+ cout << ", " << v[i];
+ }
+
+ cout << ")" << endl;
+
+ permute(v);
+
+ }
+
+ cout << "Output: 0\n";
+
+ return 0;
+
+}
diff --git a/challenge-085/pkmnx/c++/ch-1/sample.input b/challenge-085/pkmnx/c++/ch-1/sample.input
new file mode 100644
index 0000000000..0c56ca41e6
--- /dev/null
+++ b/challenge-085/pkmnx/c++/ch-1/sample.input
@@ -0,0 +1,4 @@
+0.5
+1.1
+0.3
+0.7
diff --git a/challenge-085/pkmnx/c++/ch-2/Makefile b/challenge-085/pkmnx/c++/ch-2/Makefile
new file mode 100644
index 0000000000..daa4fd0e5f
--- /dev/null
+++ b/challenge-085/pkmnx/c++/ch-2/Makefile
@@ -0,0 +1,4 @@
+all:
+ g++ -o ch-2 ch-2.cpp -Wall -pedantic -ansi
+clean:
+ rm *.o
diff --git a/challenge-085/pkmnx/c++/ch-2/ch-2.cpp b/challenge-085/pkmnx/c++/ch-2/ch-2.cpp
new file mode 100644
index 0000000000..bcb18bbd92
--- /dev/null
+++ b/challenge-085/pkmnx/c++/ch-2/ch-2.cpp
@@ -0,0 +1,47 @@
+#include <bits/stdc++.h>
+#include <iostream>
+#include <math.h>
+
+using namespace std;
+
+int main() {
+
+ long n;
+ cin >> n;
+
+ if ( n < 0 ) {
+ cout << "Input: " << n << " is not positive." << endl;
+ exit(0);
+ }
+ if ( n > INT_MAX ) {
+ cout << "Input: " << n << " is greater than INT_MAX: " << INT_MAX << endl;
+ exit(0);
+ }
+
+ cout << "Input: " << n << endl;
+
+ for ( int i = 2; i <= n; ++i ) {
+ if ( n % i == 0 ) {
+
+ for ( int j = 2; j < INT_MAX; j++ ) {
+
+ long ij = 1;
+ for ( int k = 0; k < j; k++ ) {
+ ij *= i;
+ if ( ij > n ) { break; }
+ }
+ if ( ij > n ) { break; }
+
+ if ( ij == n ) {
+ cout << "Output: 1 as " << n << " = " << i << " ^ " << j << endl;
+ exit(0);
+ }
+
+ }
+
+ }
+ }
+
+ cout << "Output: 0" << endl;
+ return 0;
+}