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:
if cols='' | cols=="," then cols= 16 /* " " " " " " */
call hdrs /*display the (two) headers to the term*/
!= '║' do r=1 by 2 to rows; _= right(r, 3) /*definebuild odd an(numbered) externalrows gridof bordera glyphtable.*/
do r=1 by 2 to rows do c=0 to cols /*build odd[↓] (numbered) rowsbuild ofa column for a table row.*/
$= right(r, 3) _= _ ! right(jacobi(c, r), 2); != '│' /*showreset grid anend indexchar.*/
doend c=0 to cols; $= $ ! right(jacobi(c, r), 2) /*build a columnc*/
say _ '║'; != '' /*display a table row; /*reset endgrid charglyph*/
end /*ar*/
say $ '║'; != '║' /*display a table row; reset grid glyph*/
end /*n*/
 
say translate(@.2, '╩╧╝', "╬╤╗") /*display the bottom of the grid border*/
exit /*stick a fork in it, we're all done. */
Line 257 ⟶ 254:
@.2= '════╬'; do c=0 to cols; @.2= @.2 || "════╤" ; end
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***'; $ = 1 result = 1 /*define result.*/
if n//2==0 then do; say er n " must be a positive odd integer."; exit 13
end
a= a // n /*in REXX, //*obtain isA modulus for non-negN A*/
do while a\==0 /*perform while A isn't zero. */
 
do while a\==0 do while a//2==0; a= a % 2 /*perform whiledivide A isn't zero. (as a integer) by 2 */
if do while an//28==0 3 | n//*8==5 then "$= -$ " A is even. /*use N mod 8 */
a= a % 2 end /*inwhile REXX, % is the same as int. div.a//2==0*/
parse value a n with nn= n // 8 a /*obtain N modulus eight. swap values of variables: A N */
if nna//4==3 |& nnn//4==53 then result$= -result$
a= a // endn
end /*nwhile a\==0*/
 
if n==1 then return result$
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>
{{out|output|text=&nbsp; when using the default inputs:}}