Primality by trial division: Difference between revisions

Content added Content deleted
(→‎{{header|Quackery}}: improved efficiency)
Line 3,270: Line 3,270:


=={{header|Quackery}}==
=={{header|Quackery}}==
<lang Quackery>[ dup 1
[ 2dup > while
+ 1 >>
2dup / again ]
drop nip ] is sqrt ( n --> n )


<code>sqrt</code> is defined at [[Isqrt (integer square root) of X#Quackery]].
[ dup 2 = iff

[ drop true ] done
dup 2 < iff
<lang Quackery> [ dup 4 < iff [ 1 > ] done
[ drop false ] done
dup 1 & not iff [ drop false ] done
dup ~ 1 & iff
true swap dup sqrt
[ drop false ] done
0 = iff [ 2drop not ] done
1 >> times
true swap
dup sqrt 1 - times
[ dup i^ 1 << 3 + mod 0 = if
[ dup i^ 2 + mod 0 = if
[ dip not conclude ] ]
drop ] is prime ( n --> b )
[ dip not conclude ] ]
drop ] is isprime ( n --> b )
</lang>
</lang>