Primes whose sum of digits is 25: Difference between revisions

Content added Content deleted
m (C++ - minor performance improvement)
Line 204: Line 204:
}
}


void count_all(const std::string& str, int rem, int& count) {
int count_all(const std::string& str, int rem) {
int count = 0;
if (rem == 0) {
if (rem == 0) {
switch (str.back()) {
switch (str.back()) {
Line 219: Line 220:
} else {
} else {
for (int i = 1; i <= std::min(9, rem); ++i)
for (int i = 1; i <= std::min(9, rem); ++i)
count_all(str + std::to_string(i), rem - i, count);
count += count_all(str + char('0' + i), rem - i);
}
}
return count;
}
}


Line 236: Line 238:
std::cout << '\n';
std::cout << '\n';


count = 0;
auto start = std::chrono::steady_clock::now();
auto start = std::chrono::steady_clock::now();
count_all("", 25, count);
count = count_all("", 25);
auto end = std::chrono::steady_clock::now();
auto end = std::chrono::steady_clock::now();
std::cout << "\nThere are " << count
std::cout << "\nThere are " << count