Anonymous user
Magnanimous numbers: Difference between revisions
m
→{{header|REXX}}: optimized the GENP subroutine.
m (→{{header|REXX}}: optimized the GENP subroutine.) |
|||
Line 1,363:
=={{header|REXX}}==
The majority of the time consumed was in generating a list (sparse array) of suitable primes.
<br>The '''magna''' function (magnanimous) was quite simple to code and pretty fast, it includes the 1<sup>st</sup> and last digit parity test.
<br>By far, the most CPU time was in the generation of primes.
Line 1,378 ⟶ 1,377:
if HI=='' then HI= LO /*Just a single number? Then use LO. */
if HI==0 then iterate /*Is HI a zero? Then skip this range.*/
do k=0 until
if \magna(k) then iterate
if
end /*k*/
say
say center(' 'LO "──►" HI 'magnanimous numbers ', 126, "─")
say strip($)
end /*j*/
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
magna: procedure expose @. !.; parse arg x 1 L 2 '' -1 R /*obtain #, 1st & last digit.*/
Line 1,400 ⟶ 1,399:
return 1 /*Pass all the tests, it's magnanimous.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6=
!.= 0; !.2=1; !.3=1; !.5=1; !.7=1; !.11=1; !.13=1 /*
do j=@.#+4 by 2 to highP; parse var j '' -1 _; if _==5 then iterate /*
if j// 3==0 then iterate; if j// 7==0 then
if j//
if j//
end
#= #+1;
end
{{out|output|text= when using the default inputs:}}
<pre>
|