Unprimeable numbers: Difference between revisions

Content added Content deleted
(→‎{{header|Wren}}: Now uses Wren-math module.)
(→‎{{header|REXX}}: simplified parts of the program, optimized for speed.)
Line 1,775: Line 1,775:
if !.new then iterate j /*This new number a prime? " " */
if !.new then iterate j /*This new number a prime? " " */
end /*e_*/
end /*e_*/

meat= right(j, L-1) /*obtain the last L-1 digits of J. */
/* [↑] examine a new 1st digit of J. */
/* [↑] examine a new 1st digit of J. */
do f_=0 for 10; new= (f_||meat) + 0 /*obtain a different number (than J).*/
do f_=0 for 10; new= (f_||meat) + 0 /*obtain a different number (than J).*/
Line 1,794: Line 1,792:
if #<=n then $$= $$ commas(j) /*maybe add unprimeable # to $$ list.*/
if #<=n then $$= $$ commas(j) /*maybe add unprimeable # to $$ list.*/
if #==x then $.ox= commas(j) /*assign the Xth unprimeable number.*/
if #==x then $.ox= commas(j) /*assign the Xth unprimeable number.*/
_= right(j, 1) /*obtain the right─most dec digit of J.*/
parse var j '' -1 _ /*obtain the right─most dec digit of J.*/
if $._==. then $._= j /*the 1st unprimeable # that ends in _.*/
if $._==. then $._= j /*the 1st unprimeable # that ends in _.*/
if $.3==. then iterate; if $.7==. then iterate /*test if specific #'s found.*/
if $.3==. then iterate; if $.7==. then iterate /*test if specific #'s found.*/
Line 1,814: Line 1,812:
th:procedure;parse arg x;return x||word('th st nd rd',1+(x//10)*(x//100%10\==1)*(x//10<4))
th:procedure;parse arg x;return x||word('th st nd rd',1+(x//10)*(x//100%10\==1)*(x//10<4))
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6= 13; nP=6 /*assign low primes; # primes. */
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6= 13; @.7=17; @.8=19; @.9=23; @.10=29; #p=10
!.=0; !.2=1; !.3=1; !.5=1; !.7=1; !.11=1 /*assign some low semaphore primes. */
!.=0; !.2=1; !.3=1; !.5=1; !.7=1; !.11=1; !.13=1; !.17=1; !.19=1; !.23=1; !.29=1
do lim=100 until lim*lim>=hp; end /*only keep primes up to the sqrt(hp). */
do lim=100 until lim*lim>=hp /*only keep primes up to the sqrt(hp). */
do j=@.nP+4 by 2 to hp /*only find odd primes from here on. */
end /*lim*/ /* [↑] find limit for storing primes. */
if j// 3==0 then iterate /*is J divisible by #3 Then not prime*/
do j=@.#p+2 by 2 to hp /*only find odd primes from here on. */
parse var j '' -1 _;if _==5 then iterate /*Is last digit a "5"? " " " */
parse var j '' -1 _;if _==5 then iterate /*Get last digit; is last digit a "5" ?*/
if j// 7==0 then iterate /*is J divisible by 7? " " " */
if j// 3==0 then iterate /*is J divisible by 3? Then not prime*/
if j// 7==0 then iterate /* " " " " 7? " " " */
if j//11==0 then iterate /* " " " " 11? " " " */
if j//11==0 then iterate /* " " " " 11? " " " */
if j//13==0 then iterate /*is " " " 13? " " " */
if j//13==0 then iterate /* " " " " 13? " " " */
do k=7 while k*k<=j /*divide by some generated odd primes. */
if j//17==0 then iterate /* " " " " 17? " " " */
if j//19==0 then iterate /* " " " " 19? " " " */
if j//23==0 then iterate /* " " " " 23? " " " */
if j//29==0 then iterate /* " " " " 29? " " " */
do k=11 while k*k<=j /*divide by some generated odd primes. */
if j // @.k==0 then iterate j /*Is J divisible by P? Then not prime*/
if j // @.k==0 then iterate j /*Is J divisible by P? Then not prime*/
end /*k*/ /* [↓] a prime (J) has been found. */
end /*k*/ /* [↓] a prime (J) has been found. */
nP= nP+1; if nP<=lim then @.nP=j; !.j=1 /*bump prime count; assign prime to @.*/
#p= #p+1; if #p<=lim then @.#p=j; !.j=1 /*bump prime count; assign prime to @.*/
end /*j*/; return</lang>
end /*j*/; return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}