Frobenius numbers: Difference between revisions

m
→‎{{header|REXX}}: changed/add comments and whitespace, made code simplier, moved a line of code to the mainline.
(Added XPL0 example.)
m (→‎{{header|REXX}}: changed/add comments and whitespace, made code simplier, moved a line of code to the mainline.)
Line 988:
if hi=='' | hi=="," then hi= 10000 /* " " " " " " */
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 10 /*the width of any column in the output*/
call genP /*build array of semaphores for primes.*/
@Frobtitle= ' Frobenius numbers that are < ' commas(hi)
if cols>0 then say ' index │'center(@Frobtitle, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
$=; idx= 1 /*list of Frobenius #s (so far); index.*/
do j=1; jp= j+1; y= @.j*@.jp - @.j - @.jp /*calculate a Frobenius number. */
if y>= hi then leave /*Is Y too high? Yes, then leave. */
if cols==<0 then iterate /*Build the list (to be shown later)? */
c= commas(y) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) ) /*add a Frobenius #──►list, allow big #*/
Line 1,006 ⟶ 1,007:
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' commas(j-1) @FROBtitle
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 1,012 ⟶ 1,013:
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6= 13 /*define some low primes. */
w= 10; #=6; s.#= @.# **2 /*number of primes so far; prime²*/
/* [↓] generate more primes ≤ high.*/
do j=@.#+4 by 2 to hi+1 /*find odd primes from here on. */
Line 1,024 ⟶ 1,025:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j /*bump # Ps; assign next P; P squared*/
end /*j*/; return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>