aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Russell <ac.russell@live.com>2021-10-17 18:01:01 -0400
committerAdam Russell <ac.russell@live.com>2021-10-17 18:01:01 -0400
commit13533b4d5f965fcd819f3b8a6d23afe363f74478 (patch)
treea47db525f4b488aa67aa64eeb954844d56f6ea53
parente9dbf6d87ca9e091612a88bbc72abd6ba3c56831 (diff)
downloadperlweeklychallenge-club-13533b4d5f965fcd819f3b8a6d23afe363f74478.tar.gz
perlweeklychallenge-club-13533b4d5f965fcd819f3b8a6d23afe363f74478.tar.bz2
perlweeklychallenge-club-13533b4d5f965fcd819f3b8a6d23afe363f74478.zip
updated C++ solution to part 1
-rw-r--r--challenge-134/adam-russell/cxx/ch-1.cxx15
-rw-r--r--challenge-134/adam-russell/nuweb/ch-1.w15
2 files changed, 6 insertions, 24 deletions
diff --git a/challenge-134/adam-russell/cxx/ch-1.cxx b/challenge-134/adam-russell/cxx/ch-1.cxx
index 4a32d8255e..f6c9c935f6 100644
--- a/challenge-134/adam-russell/cxx/ch-1.cxx
+++ b/challenge-134/adam-russell/cxx/ch-1.cxx
@@ -20,21 +20,12 @@ std::vector<int> Pandigital::first_n_pandigitals(int n) {
int x = 1000000000;
do {
int test = x;
- std::vector<int> test_vector;
+ std::vector<int> test_vector = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
do {
- test_vector.push_back(test % 10);
+ test_vector.erase(std::remove(test_vector.begin(), test_vector.end(), test % 10), test_vector.end());
test = test / 10;
} while(test > 0);
- if(std::count(test_vector.begin(), test_vector.end(), 0) &&
- std::count(test_vector.begin(), test_vector.end(), 1) &&
- std::count(test_vector.begin(), test_vector.end(), 2) &&
- std::count(test_vector.begin(), test_vector.end(), 3) &&
- std::count(test_vector.begin(), test_vector.end(), 4) &&
- std::count(test_vector.begin(), test_vector.end(), 5) &&
- std::count(test_vector.begin(), test_vector.end(), 6) &&
- std::count(test_vector.begin(), test_vector.end(), 7) &&
- std::count(test_vector.begin(), test_vector.end(), 8) &&
- std::count(test_vector.begin(), test_vector.end(), 9))
+ if(test_vector.size() == 0)
pandigitals.push_back(x);
x++;
} while(pandigitals.size() < n);
diff --git a/challenge-134/adam-russell/nuweb/ch-1.w b/challenge-134/adam-russell/nuweb/ch-1.w
index c0052ff3d2..ec1cfb79e4 100644
--- a/challenge-134/adam-russell/nuweb/ch-1.w
+++ b/challenge-134/adam-russell/nuweb/ch-1.w
@@ -136,21 +136,12 @@ Write a script to generate first 5 Pandigital Numbers in base 10.
@d check if pandigital
@{
int test = x;
- std::vector<int> test_vector;
+ std::vector<int> test_vector = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
do{
- test_vector.push_back(test % 10);
+ test_vector.erase(std::remove(test_vector.begin(), test_vector.end(), test % 10), test_vector.end());
test = test / 10;
}while(test > 0);
- if(std::count(test_vector.begin(), test_vector.end(), 0) &&
- std::count(test_vector.begin(), test_vector.end(), 1) &&
- std::count(test_vector.begin(), test_vector.end(), 2) &&
- std::count(test_vector.begin(), test_vector.end(), 3) &&
- std::count(test_vector.begin(), test_vector.end(), 4) &&
- std::count(test_vector.begin(), test_vector.end(), 5) &&
- std::count(test_vector.begin(), test_vector.end(), 6) &&
- std::count(test_vector.begin(), test_vector.end(), 7) &&
- std::count(test_vector.begin(), test_vector.end(), 8) &&
- std::count(test_vector.begin(), test_vector.end(), 9))
+ if(test_vector.size() == 0)
pandigitals.push_back(x);
@}