aboutsummaryrefslogtreecommitdiff
path: root/challenge-085/pkmnx/c++
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2020-11-08 19:40:05 +0100
committerAbigail <abigail@abigail.be>2020-11-08 19:40:05 +0100
commit4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1 (patch)
tree52495c7853bf31c427ec26f500c66c5bed6753b4 /challenge-085/pkmnx/c++
parent520db2cfca438cdc9a78932e5f479e28abee150b (diff)
parentff7475c4559b1087f402725a7c526d3f780e3434 (diff)
downloadperlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.tar.gz
perlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.tar.bz2
perlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-085/pkmnx/c++')
-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;
+}