Jump to content

Rare numbers: Difference between revisions

m
→‎The task: added "%10" where needed. Without it, the progam fails to produce a result where "n+r" has the first digit of "1".
m (→‎The task: added "%10" where needed. Without it, the progam fails to produce a result where "n+r" has the first digit of "1".)
Line 599:
p=([]{int g{z/2}; std::array<long,(z+1)/2>n{}; for(auto& i:n) if (z%2==1&n[0]==0) i=2*pow10[z/2]; else {i=pow10[z-g]+pow10[g-1]; --g;} return n;})()]() mutable{
for (auto g=n.begin();g<(n.end());++g) if (*g<19&(z%2==0|n[0]<10)){
*g+=1; while(!r1[n[(z+1)/2-1]%10]) *g+=1; return std::optional{std::inner_product(n.begin(),n.end(),p.begin(),0L)};} else *g=0;
return std::optional<long>{};}));
std::cout<<"Rare numbers of length "<<z<<std::endl;
Line 687:
 
</pre>
 
===10 to 19 digits===
The following is a faster implementation of the algorithm. It compiles with both g++ and clang++, both produce the correct output. It will not work for lengths less than 10 or greater than 19. The timings are using Mingw running on a Core I5 1035G1.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.