Humble numbers: Difference between revisions
Content added Content deleted
Catskill549 (talk | contribs) |
(→{{header|C sharp|C#}}: Added Direct Generation) |
||
Line 422: | Line 422: | ||
1272 have 8 digits |
1272 have 8 digits |
||
1767 have 9 digits</pre> |
1767 have 9 digits</pre> |
||
== Direct Generation == |
|||
{{trans|Go}} |
|||
{{libheader|System.Numerics}} |
|||
<lang csharp>#define BI |
|||
using System; |
|||
using System.Collections.Generic; |
|||
#if BI |
|||
using UI = System.Numerics.BigInteger; |
|||
#else |
|||
using UI = System.UInt64; |
|||
#endif |
|||
class Program { |
|||
static void Main(string[] args) { |
|||
#if BI |
|||
const int max = 100; |
|||
#else |
|||
const int max = 19; |
|||
#endif |
|||
List<UI> h = new List<UI> { 1 }; |
|||
UI x2 = 2, x3 = 3, x5 = 5, x7 = 7, hm = 2, lim = 10; |
|||
int i = 0, j = 0, k = 0, l = 0, lc = 0, d = 1; |
|||
Console.WriteLine("Digits Count Time Mb used"); |
|||
var elpsd = -DateTime.Now.Ticks; |
|||
do { |
|||
h.Add(hm); |
|||
if (hm == x2) x2 = h[++i] << 1; |
|||
if (hm == x3) x3 = (h[++j] << 1) + h[j]; |
|||
if (hm == x5) x5 = (h[++k] << 2) + h[k]; |
|||
if (hm == x7) x7 = (h[++l] << 3) - h[l]; |
|||
hm = x2; if (x3 < hm) hm = x3; if (x5 < hm) hm = x5; if (x7 < hm) hm = x7; |
|||
if (hm >= lim) { |
|||
Console.WriteLine("{0,3} {1,9:n0} {2,9:n0} ms {3,9:n0}", d, h.Count - lc, |
|||
(elpsd + DateTime.Now.Ticks) / 10000, GC.GetTotalMemory(false) / 1000000); |
|||
lc = h.Count; if (++d > max) break; lim *= 10; |
|||
} |
|||
} while (true); |
|||
Console.WriteLine("{0,13:n0} Total", lc); |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
BigIntegers: (tabulates up to 100 digits in about 3/4 of a minute, but a lot of memory is consumed - 4.2 GB) |
|||
<pre style="height:64ex;overflow:scroll">Digits Count Time Mb used |
|||
1 9 5 ms 0 |
|||
2 36 7 ms 0 |
|||
3 95 7 ms 0 |
|||
4 197 7 ms 0 |
|||
5 356 7 ms 0 |
|||
6 579 8 ms 0 |
|||
7 882 8 ms 0 |
|||
8 1,272 9 ms 0 |
|||
9 1,767 9 ms 1 |
|||
10 2,381 11 ms 2 |
|||
11 3,113 13 ms 3 |
|||
12 3,984 16 ms 1 |
|||
13 5,002 19 ms 4 |
|||
14 6,187 26 ms 2 |
|||
15 7,545 30 ms 6 |
|||
16 9,081 37 ms 4 |
|||
17 10,815 45 ms 3 |
|||
18 12,759 52 ms 11 |
|||
19 14,927 68 ms 4 |
|||
20 17,323 78 ms 7 |
|||
21 19,960 98 ms 6 |
|||
22 22,853 123 ms 16 |
|||
23 26,015 162 ms 10 |
|||
24 29,458 184 ms 14 |
|||
25 33,188 217 ms 14 |
|||
26 37,222 256 ms 24 |
|||
27 41,568 289 ms 28 |
|||
28 46,245 335 ms 30 |
|||
29 51,254 389 ms 23 |
|||
30 56,618 433 ms 26 |
|||
31 62,338 479 ms 49 |
|||
32 68,437 551 ms 39 |
|||
33 74,917 603 ms 47 |
|||
34 81,793 689 ms 48 |
|||
35 89,083 759 ms 53 |
|||
36 96,786 872 ms 56 |
|||
37 104,926 991 ms 58 |
|||
38 113,511 1,108 ms 99 |
|||
39 122,546 1,250 ms 104 |
|||
40 132,054 1,377 ms 107 |
|||
41 142,038 1,512 ms 101 |
|||
42 152,515 1,637 ms 106 |
|||
43 163,497 1,777 ms 112 |
|||
44 174,986 1,938 ms 121 |
|||
45 187,004 2,140 ms 165 |
|||
46 199,565 2,266 ms 177 |
|||
47 212,675 2,403 ms 187 |
|||
48 226,346 2,571 ms 194 |
|||
49 240,590 2,745 ms 209 |
|||
50 255,415 2,945 ms 223 |
|||
51 270,843 3,176 ms 236 |
|||
52 286,880 3,391 ms 248 |
|||
53 303,533 3,660 ms 395 |
|||
54 320,821 3,891 ms 414 |
|||
55 338,750 4,131 ms 428 |
|||
56 357,343 4,423 ms 443 |
|||
57 376,599 4,702 ms 460 |
|||
58 396,533 5,110 ms 418 |
|||
59 417,160 5,450 ms 438 |
|||
60 438,492 5,764 ms 464 |
|||
61 460,533 6,146 ms 489 |
|||
62 483,307 6,511 ms 513 |
|||
63 506,820 7,097 ms 545 |
|||
64 531,076 7,774 ms 706 |
|||
65 556,104 8,250 ms 740 |
|||
66 581,902 8,766 ms 771 |
|||
67 608,483 9,225 ms 805 |
|||
68 635,864 9,755 ms 842 |
|||
69 664,053 10,423 ms 882 |
|||
70 693,065 10,975 ms 918 |
|||
71 722,911 11,554 ms 961 |
|||
72 753,593 12,302 ms 1,000 |
|||
73 785,141 12,974 ms 1,047 |
|||
74 817,554 13,650 ms 1,092 |
|||
75 850,847 14,322 ms 1,140 |
|||
76 885,037 15,164 ms 1,724 |
|||
77 920,120 15,934 ms 1,776 |
|||
78 956,120 16,731 ms 1,834 |
|||
79 993,058 17,591 ms 1,901 |
|||
80 1,030,928 18,498 ms 1,966 |
|||
81 1,069,748 19,438 ms 2,037 |
|||
82 1,109,528 20,740 ms 1,839 |
|||
83 1,150,287 21,676 ms 1,911 |
|||
84 1,192,035 22,737 ms 1,985 |
|||
85 1,234,774 23,806 ms 2,067 |
|||
86 1,278,527 24,897 ms 2,147 |
|||
87 1,323,301 26,009 ms 2,235 |
|||
88 1,369,106 27,173 ms 2,322 |
|||
89 1,415,956 28,399 ms 2,411 |
|||
90 1,463,862 30,640 ms 3,041 |
|||
91 1,512,840 31,918 ms 3,138 |
|||
92 1,562,897 33,236 ms 3,241 |
|||
93 1,614,050 34,657 ms 3,339 |
|||
94 1,666,302 36,186 ms 3,451 |
|||
95 1,719,669 37,722 ms 3,560 |
|||
96 1,774,166 39,222 ms 3,673 |
|||
97 1,829,805 40,801 ms 3,800 |
|||
98 1,886,590 42,447 ms 3,933 |
|||
99 1,944,540 44,142 ms 4,077 |
|||
100 2,003,661 45,964 ms 4,221 |
|||
51,428,827 Total</pre> |
|||
UInt64s: (comment out "'''#define BI'''" at the top of the code) |
|||
<pre>Digits Count Time Mb used |
|||
1 9 6 ms 0 |
|||
2 36 7 ms 0 |
|||
3 95 7 ms 0 |
|||
4 197 7 ms 0 |
|||
5 356 7 ms 0 |
|||
6 579 8 ms 0 |
|||
7 882 8 ms 0 |
|||
8 1,272 8 ms 0 |
|||
9 1,767 8 ms 0 |
|||
10 2,381 8 ms 0 |
|||
11 3,113 8 ms 0 |
|||
12 3,984 8 ms 0 |
|||
13 5,002 8 ms 0 |
|||
14 6,187 8 ms 0 |
|||
15 7,545 9 ms 1 |
|||
16 9,081 9 ms 1 |
|||
17 10,815 9 ms 1 |
|||
18 12,759 10 ms 2 |
|||
19 14,927 10 ms 2 |
|||
80,987 Total</pre> |
|||
=={{header|C++}}== |
=={{header|C++}}== |