Anonymous user
Chinese remainder theorem: Difference between revisions
m
→algebraic: added whitespace and comments.
m (changed >/pre> to </pre> in the freebasic entry) |
m (→algebraic: added whitespace and comments.) |
||
Line 2,154:
<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); N= N * n.j
a.j= word(As, j)
end /*j*/
do x=1 for N /*use a simple algebraic method. */
Line 2,174:
end /*i*/ /* [↑] limit solution to the product. */
say 'found a solution with X=' x /*display one possible solution. */
exit
end /*x*/
|