Primes whose sum of digits is 25: Difference between revisions
Content added Content deleted
(→Stretch Goal: typo) |
m (C++ - minor performance improvement) |
||
Line 204: | Line 204: | ||
} |
} |
||
int count_all(const std::string& str, int rem) { |
|||
⚫ | |||
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 + |
count += count_all(str + char('0' + i), rem - i); |
||
} |
} |
||
return count; |
|||
} |
} |
||
Line 236: | Line 238: | ||
std::cout << '\n'; |
std::cout << '\n'; |
||
⚫ | |||
auto start = std::chrono::steady_clock::now(); |
auto start = std::chrono::steady_clock::now(); |
||
count_all("", 25 |
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 |