Anonymous user
Truncatable primes: Difference between revisions
m
→{{header|REXX}}: simplified the code, added/changed whitespace and comments, used a template for the output section.
(Rewrite Pike code to be simpler and faster) |
m (→{{header|REXX}}: simplified the code, added/changed whitespace and comments, used a template for the output section.) |
||
Line 2,628:
Extra code was added to the prime number generator as this is the section of the REXX program that consumes the vast majority of the computation time.
<lang REXX>/*REXX program finds largest left─ and right─truncatable primes ≤ 1m (or argument 1).*/
parse arg
!.= 0;
@.1=2; @.2=3; @.3=5; @.4=7; @.5=11
!.2=1; !.3=1; !.5=1; !.7=1; !.11=1
/* [↓] generate more primes ≤ high.*/
/* [↑] the above five lines saves time*/
/* [↓] find largest left truncatable P*/
do L=# by -1 for #
leave /*egress, found left truncatable prime.*/
end /*L*/
/* [↓] find largest right truncated P.*/
do R=# by -1 for #
leave /*egress, found right truncatable prime*/
end
/*stick
say 'The
say
▲'''output''' when using the default input:
<pre>
The largest left─truncatable prime ≤ 1000000 is 998443
The largest right─truncatable prime ≤ 1000000 is 739399
|