Jacobi symbol: Difference between revisions

Content deleted Content added
→‎{{header|REXX}}: added the REXX computer programming language for this task.
m →‎{{header|REXX}}: simplified code, aligned some statements, added comments.
Line 253: Line 253:
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
hdrs: @.1= 'n/a ║'; do c=0 to cols; @.1= @.1 || right(c, 3)" "; end
hdrs: @.1= 'n/a ║'; do c=0 to cols; @.1= @.1 || right(c, 3)" "; end
L1= length(@.1); !!= '╗'; @.1= left(@.1, L1-1) ; say @.1
L= length(@.1); @.1= left(@.1, L - 1) ; say @.1
@.2= '════╬'; do c=0 to cols; @.2= @.2 || "════╤" ; end
@.2= '════╬'; do c=0 to cols; @.2= @.2 || "════╤" ; end
L2= length(@.2); !!= '╗'; @.2= left(@.2, L2-1)"╗" ; say @.2
L= length(@.2); @.2= left(@.2, L - 1)"╗" ; say @.2
!!= '╝'; return
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
jacobi: procedure; parse arg a,n
jacobi: procedure; parse arg a,n; er= '***error***'; result = 1
if n//2==0 then do; say '***error*** ' n " must be a positive odd integer."
if n//2==0 then do; say er n " must be a positive odd integer."; exit 13
exit 13
end
end
a= a // n /*in REXX, // is modulus for non-neg A*/
a= a // n /*in REXX, // is modulus for non-neg A*/
result = 1


do while a\==0 /*perform while A isn't zero. */
do while a\==0 /*perform while A isn't zero. */
Line 273: Line 271:
end
end


parse value a n with n a /*swap values of variables: A N */
parse value a n with n a /*swap values of variables: A N */
if a//4==3 & n//4==3 then result= -result
if a//4==3 & n//4==3 then result= -result
a= a // n
a= a // n