Anonymous user
Sum and product puzzle: Difference between revisions
m
→version 5, fast: changed some comments.
m (→version 5, fast: added a message if there wasn't a solution found.) |
m (→version 5, fast: changed some comments.) |
||
Line 2,756:
This REXX version is over '''ten''' times faster than the previous REXX version.
<lang rexx>/*REXX program solves the Sum and Product Puzzle (also known as the Impossible Puzzle).*/
@.= 0;
do j=5 by 2 to
do k=3 while k*k<=j; if j//k==0 then iterate j /*J ÷ by K ? */
end /*k*/; @.j= 1 /*found a net prime number:
end /*j*/
@.2=1 /*assign the even prime, ex post facto.*/
do s=2 for
$= 0; do m=2 for s%2 -1 /* [↓] check for uniqueness of product*/
if C2(m * (s-m)) then do; if $>0 then iterate s; $= m; end
Line 2,775:
end; /*a*/; return 1
/*──────────────────────────────────────────────────────────────────────────────────────*/
C2: procedure expose @.
do j=2 while j*j<p /*perform up to the square root of P. */
if p//j==0 then do; q= p % j
if q>=2 then if q<=
else $= 1
end
end /*j*/; return $</lang>
{{out|output|text= when using the default internal input:}}
<pre>
The numbers are: 4 and 13
|