Klarner-Rado sequence: Difference between revisions

Add SETL
(Add Refal)
(Add SETL)
Line 1,928:
The 1000000 th element of Klarner-Rado sequence is 54381285
</pre>
 
=={{header|SETL}}==
{{works with|GNU SETL}}
 
Abusing the set mechanism makes this very straightforward, without incurring a terrible performance hit: finding a million items takes 5 seconds on a 2.6GHz Core 2 Duo.
 
<syntaxhighlight lang="setl">program Klarner_Rado_sequence;
init K := kr(10**6);
 
print('First 100 Klarner-Rado sequence numbers:');
loop for n in K(1..100) do
nprint(lpad(str n, 5));
if (c +:= 1) mod 10 = 0 then
print;
end if;
end loop;
 
loop for p in [3..6] do
n := 10**p;
print('The ' + str n + 'th Klarner-Rado number is '
+ str K(n) + '.');
end loop;
 
proc kr(amt);
seq := [];
prc := {1};
loop while #seq < amt do
n from prc;
seq with:= n;
prc with:= 2*n + 1;
prc with:= 3*n + 1;
end loop;
return seq;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre>
First 100 Klarner-Rado sequence numbers:
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 Klarner-Rado number is 8487.
The 10000th Klarner-Rado number is 157653.
The 100000th Klarner-Rado number is 2911581.
The 1000000th Klarner-Rado number is 54381285.</pre>
 
=={{header|Visual Basic .NET}}==
2,114

edits