Motzkin numbers: Difference between revisions

m
→‎{{header|REXX}}: changed whitespace and comments.
m (→‎{{header|REXX}}: changed whitespace and comments.)
Line 830:
say center('' , w, "─") center('' , wm, "─") center('', 11, "─")
@.= 1 /*define default vale for the @. array.*/
do m=0 for n /*step through indices for Motzkin #'s.*/
if m>1 then @.m= (@(m-1)*(m+m+1) + @(m-2)*(m*3-3))%(m+2) /*calculate a Motzkin #*/
call show /*display thea Motzkin number ──► term. terminal*/
end /*m*/
 
say center('' , w, "─") center('' , wm, "─") center('', 11, "─")
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
@: parse arg i; return @.i return @.i /*return function expression based on I*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
prime: if isPrime(@.m) then return " prime"; return ''
show: y= commas(@.m); say right(m, w) right(y, max(wm, length(y))) prime(); return
/*──────────────────────────────────────────────────────────────────────────────────────*/
isPrime: procedure expose p?. p#. p_.; parse arg x /*persistent P·· REXX variables.*/
Line 854 ⟶ 856:
if x==p?.0 then return 1 /*save a number of primality divisions.*/
parse var x '' -1 _ /*obtain right─most decimal digit of X.*/
if _ ==5 then return 0; if x//2 ==0 then return 0 /*is X ÷ by 5? X Then÷ returnby not prime.2?*/
if x//2 3==0 then return 0; if x//7 ==0 then return 0 /* " " " " 23? " " " " 7?*/
if x//3 ==0 then return 0 /* " " " " 3? " " " " */
if x//7 ==0 then return 0 /* " " " " 7? " " " " */
/*weed numbers that're ≥ 11 multiples. */
do j=5 to p?.# while p_.j<=x; if x//p#.j ==0 then return 0