Jump to content

Humble numbers: Difference between revisions

m
→‎Direct Generation - Variant: corrected typos, noted compiler options.
(Added C++ direct generation variant)
m (→‎Direct Generation - Variant: corrected typos, noted compiler options.)
Line 986:
 
=== Direct Generation - Variant ===
A direct generation variant. Rather quick, as the humble numbers are not generated in order. And the digits are not counted individually, the log representation of each humble number is just binned into the decade tally with a simple division by log(10). Note: g++ compiler options: <code>-O3 -std=c++17</code>
<lang c>#include <chrono>
#include <cmath>
Line 995:
using namespace chrono;
int limc = 100877;
const double l2 = log(2), l3 = log(3), l5 = log(5), l7 = log(7), l0 = log(10), fac = 1e12;
Line 1,003:
 
// slow way to determine whether numbers are humble numbers
static void Fisrt_SlowFirst_Slow(int firstAmt) { printf("The first %d humble numbers are: ", firstAmt);
for (int gg = 0, g = 1; gg < firstAmt; g++) if (IsHum(g)) { printf("%d ", g); gg++; }
printf("\n\n"); }
int main(int argc, char **argv) {
Fisrt_SlowFirst_Slow(50); setlocale(LC_ALL, ""); auto st = steady_clock::now();
if (argc > 1) limc = stoi(argv[1]);
UI *bins = new UI[limc], lb0 = (UI)round(fac * l0),
Line 1,026:
}</lang>
{{out}}
Seems to give correct values as compared to the pascal (modification of hamming numbers fast alternative) version. And goes noticeably faster, up to 877 digits in about 3 1/4 minutes, where as pascal was takingtakes 1 1/3 hours to get to 877 digits.
<pre style="height:64ex;overflow:scroll;width:130ex;overflow:scroll">The first 50 humble numbers are: 1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 25 27 28 30 32 35 36 40 42 45 48 49 50 54 56 60 63 64 70 72 75 80 81 84 90 96 98 100 105 108 112 120
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.