Jacobi symbol: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: simplified code, aligned some statements, added comments.)
m (→‎{{header|REXX}}: simplified program.)
Line 241: Line 241:
if cols='' | cols=="," then cols= 16 /* " " " " " " */
if cols='' | cols=="," then cols= 16 /* " " " " " " */
call hdrs /*display the (two) headers to the term*/
call hdrs /*display the (two) headers to the term*/
!= '║' /*define an external grid border glyph.*/
do r=1 by 2 to rows; _= right(r, 3) /*build odd (numbered) rows of a table.*/
do r=1 by 2 to rows /*build odd (numbered) rows of a table.*/
do c=0 to cols /* [↓] build a column for a table row.*/
$= right(r, 3) /*show an index.*/
_= _ ! right(jacobi(c, r), 2); != '│' /*reset grid end char.*/
do c=0 to cols; $= $ ! right(jacobi(c, r), 2) /*build a column*/
end /*c*/
!= '' /*reset end char*/
say _ '║'; != '' /*display a table row; reset grid glyph*/
end /*a*/
end /*r*/
say $ '║'; != '║' /*display a table row; reset grid glyph*/
end /*n*/

say translate(@.2, '╩╧╝', "╬╤╗") /*display the bottom of the grid border*/
say translate(@.2, '╩╧╝', "╬╤╗") /*display the bottom of the grid border*/
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
Line 257: Line 254:
@.2= '════╬'; do c=0 to cols; @.2= @.2 || "════╤" ; end
@.2= '════╬'; do c=0 to cols; @.2= @.2 || "════╤" ; end
L= length(@.2); @.2= left(@.2, L - 1)"╗" ; say @.2
L= length(@.2); @.2= left(@.2, L - 1)"╗" ; say @.2
return
!= '║' ; return /*define an external grid border glyph.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
jacobi: procedure; parse arg a,n; er= '***error***'; result = 1
jacobi: procedure; parse arg a,n; er= '***error***'; $ = 1 /*define result.*/
if n//2==0 then do; say er n " must be a positive odd integer."; exit 13
if n//2==0 then do; say er n " must be a positive odd integer."; exit 13
end
end
a= a // n /*in REXX, // is modulus for non-neg A*/
a= a // n /*obtain A modulus N */
do while a\==0 /*perform while A isn't zero. */

do while a\==0 /*perform while A isn't zero. */
do while a//2==0; a= a % 2 /*divide A (as a integer) by 2 */
do while a//2==0 /* " " A is even. */
if n//8==3 | n//8==5 then $= -$ /*use N mod 8 */
a= a % 2 /*in REXX, % is the same as int. div.*/
end /*while a//2==0*/
nn= n // 8 /*obtain N modulus eight. */
parse value a n with n a /*swap values of variables: A N */
if nn==3 | nn==5 then result= -result
if a//4==3 & n//4==3 then $= -$
end
a= a // n
end /*while a\==0*/

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

if n==1 then return result
return 0</lang>
return 0</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}