Klarner-Rado sequence: Difference between revisions
Content added Content deleted
m (→EasyLang) |
(New post.) |
||
Line 522: | Line 522: | ||
54381285 |
54381285 |
||
1031926801</pre> |
1031926801</pre> |
||
=={{header|C++}}== |
|||
<syntaxhighlight lang="c++"> |
|||
#include <algorithm> |
|||
#include <cstdint> |
|||
#include <iomanip> |
|||
#include <iostream> |
|||
#include <vector> |
|||
std::vector<uint32_t> initialise_klarner_rado_sequence(const uint32_t& limit) { |
|||
std::vector<uint32_t> result(limit + 1); |
|||
uint32_t i2 = 1, i3 = 1; |
|||
uint32_t m2 = 1, m3 = 1; |
|||
for ( uint32_t i = 1; i <= limit; ++i ) { |
|||
uint32_t minimum = std::min(m2, m3); |
|||
result[i] = minimum;; |
|||
if ( m2 == minimum ) { |
|||
m2 = result[i2] * 2 + 1; |
|||
i2++; |
|||
} |
|||
if ( m3 == minimum ) { |
|||
m3 = result[i3] * 3 + 1; |
|||
i3++; |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
int main() { |
|||
const uint32_t limit = 1'000'000; |
|||
std::vector<uint32_t> klarner_rado = initialise_klarner_rado_sequence(limit); |
|||
std::cout << "The first 100 elements of the Klarner-Rado sequence:" << std::endl; |
|||
for ( uint32_t i = 1; i <= 100; ++i ) { |
|||
std::cout << std::setw(3) << klarner_rado[i] << ( i % 10 == 0 ? "\n" : " " ); |
|||
} |
|||
std::cout << std::endl; |
|||
uint32_t index = 1'000; |
|||
while ( index <= limit ) { |
|||
std::cout << "The " << index << "th element of Klarner-Rado sequence is " << klarner_rado[index] << std::endl; |
|||
index *= 10; |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
{{ out }} |
|||
<pre> |
|||
The first 100 elements of the Klarner-Rado sequence: |
|||
1 3 4 7 9 10 13 15 19 21 |
|||
22 27 28 31 39 40 43 45 46 55 |
|||
57 58 63 64 67 79 81 82 85 87 |
|||
91 93 94 111 115 117 118 121 127 129 |
|||
130 135 136 139 159 163 165 166 171 172 |
|||
175 183 187 189 190 193 202 223 231 235 |
|||
237 238 243 244 247 255 256 259 261 262 |
|||
271 273 274 279 280 283 319 327 331 333 |
|||
334 343 345 346 351 352 355 364 367 375 |
|||
379 381 382 387 388 391 405 406 409 418 |
|||
The 1000th element of Klarner-Rado sequence is 8487 |
|||
The 10000th element of Klarner-Rado sequence is 157653 |
|||
The 100000th element of Klarner-Rado sequence is 2911581 |
|||
The 1000000th element of Klarner-Rado sequence is 54381285 |
|||
</pre> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |