Blum integer: Difference between revisions

Added Quackery.
imported>Maxima enthusiast
No edit summary
(Added Quackery.)
Line 1,234:
break
</syntaxhighlight>{{out}} Same as Wren example.
 
=={{header|Quackery}}==
 
<code>sqrt</code>, <code>isprime</code>, and <code>eratosthenes</code> are defined at [[Sieve of Eratosthenes#Quackery]].
 
<code>from</code>, <code>index</code>, <code>incr</code>, and <code>end</code> are defined at [[Loops/Increment loop index within loop body#Quackery]].
 
In the line <code>600000 eratosthenes</code>, <code>600000</code> suggests foreknowledge of the value of the 26828th Blum integer, and while I was not the first person to complete this task, so knew that <code>524273</code> would suffice, I reasoned that if I had determined the generally linear relationship between <code>n</code> and <code>Blum(n)</code> from computing the first fifty Blum integers with a slower but unbounded primality test I would have felt confident that <code>600000</code> would suffice. See the graphs at https://oeis.org/A016105/graph for confirmation.
 
Precomputing the primes takes a hot minute, but the overhead is worth it for the overall speed gain.
 
<code>blum</code> returns <code>0</code> (i.e. <code>false</code>) if the number passed to it, and the value of the smaller divisor (non-zero is taken as <code>true</code>) rather than <code>false</code> and <code>true</code> (i.e. <code>1</code>) as the divisor is available without extra calculation. So as well as listing the Blum integers, their factors are shown in the output.
 
 
<syntaxhighlight lang="Quackery"> 600000 eratosthenes
 
[ dup sqrt
tuck dup * = ] is exactsqrt ( n --> n b )
 
[ dup isprime iff
[ drop false ] done
dup 4 mod 1 != iff
[ drop false ] done
dup exactsqrt iff
[ 2drop false ] done
temp put
3 from
[ 4 incr
index temp share > iff
[ drop false end ]
done
index isprime not if done
dup index /mod 0 != iff
drop done
dup isprime not iff
drop done
dip dup /
dup isprime not iff
drop done
4 mod 3 != if done
drop index end ]
temp release ] is blum ( n --> n )
 
[ dup blum
over echo
say " = "
dup echo
say " * "
/ echo cr ] is echoblum ( n --> )
 
say "The First 50 Blum integers:"
cr cr
[] 1 from
[ 4 incr
index blum if
[ index join ]
dup size 50 = if end ]
witheach echoblum
cr
say "The 26828th Blum integer:"
cr cr
0 1 from
[ 4 incr
index blum if 1+
dup 26828 = if
[ drop index end ] ]
echoblum</syntaxhighlight>
 
{{out}}
 
<pre style="height:40ex">The First 50 Blum integers:
 
21 = 3 * 7
33 = 3 * 11
57 = 3 * 19
69 = 3 * 23
77 = 7 * 11
93 = 3 * 31
129 = 3 * 43
133 = 7 * 19
141 = 3 * 47
161 = 7 * 23
177 = 3 * 59
201 = 3 * 67
209 = 11 * 19
213 = 3 * 71
217 = 7 * 31
237 = 3 * 79
249 = 3 * 83
253 = 11 * 23
301 = 7 * 43
309 = 3 * 103
321 = 3 * 107
329 = 7 * 47
341 = 11 * 31
381 = 3 * 127
393 = 3 * 131
413 = 7 * 59
417 = 3 * 139
437 = 19 * 23
453 = 3 * 151
469 = 7 * 67
473 = 11 * 43
489 = 3 * 163
497 = 7 * 71
501 = 3 * 167
517 = 11 * 47
537 = 3 * 179
553 = 7 * 79
573 = 3 * 191
581 = 7 * 83
589 = 19 * 31
597 = 3 * 199
633 = 3 * 211
649 = 11 * 59
669 = 3 * 223
681 = 3 * 227
713 = 23 * 31
717 = 3 * 239
721 = 7 * 103
737 = 11 * 67
749 = 7 * 107
 
The 26828th Blum integer:
 
524273 = 223 * 2351</pre>
 
=={{header|Raku}}==
1,462

edits