Multi-base primes: Difference between revisions
Content added Content deleted
(Added Go) |
m (Updated C++ code to match Wren/Go) |
||
Line 46: | Line 46: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
This takes |
This takes 1.1 seconds to process up to 5 character strings and 40 seconds to process up to 6 characters (3.2GHz Intel Core i5). |
||
<lang cpp>#include <algorithm> |
<lang cpp>#include <algorithm> |
||
#include <cmath> |
#include <cmath> |
||
Line 133: | Line 133: | ||
void multi_base_primes::process(const std::vector<unsigned int>& indices) { |
void multi_base_primes::process(const std::vector<unsigned int>& indices) { |
||
⚫ | |||
auto max = std::max_element(indices.begin(), indices.end()); |
auto max = std::max_element(indices.begin(), indices.end()); |
||
unsigned int min_base = 2; |
unsigned int min_base = 2; |
||
if (max != indices.end()) |
if (max != indices.end()) |
||
min_base = std::max(min_base, *max + 1); |
min_base = std::max(min_base, *max + 1); |
||
if (most_bases > max_base - min_base) |
|||
return; |
|||
⚫ | |||
for (unsigned int b = min_base; b <= max_base; ++b) { |
for (unsigned int b = min_base; b <= max_base; ++b) { |
||
uint64_t n = 0; |
uint64_t n = 0; |