Anonymous user
Chinese remainder theorem: Difference between revisions
m
→congruences sets: added comments and changed whitespace.
m (→algebraic: added whitespace and comments.) |
m (→congruences sets: added comments and changed whitespace.) |
||
Line 2,189:
<lang rexx>/*REXX program demonstrates Sun Tzu's (or Sunzi's) Chinese Remainder Theorem. */
parse arg Ns As . /*get optional arguments from the C.L. */
if Ns=='' | Ns=="," then Ns
if As=='' | As=="," then As
say 'Ns: ' Ns
say 'As: ' As;
Ns= space( translate(Ns, , ',')); #= words(Ns)
As= space( translate(As, , ',')); _= words(As)
if #\==_ then do; say "size of number sets don't match."; exit 131; end
if #==0 then do; say "size of the N set isn't valid."; exit 132; end
if _==0 then do; say "size of the A set isn't valid."; exit 133; end
N=
do j=1 for # /*process each number for As and Ns. */
n.j= word(Ns,j);
a.j= word(As,j)
end /*j*/
@.= /* [↓] converts congruences ───► sets.*/
do i=1 for #; _= a.i; @.i._= a.i; p= a.i
do N; p= p + n.i; @.i.p=
end /*
end /*i*/
/* [↓] find common number in the sets.*/
do x=1 for N; if @.1.x=='' then iterate /*locate a number. */
do v=2 to #; if @.v.x=='' then iterate x
end /*v*/
say 'found a solution with X=' x /*display one possible solution. */
exit
end /*x*/
|