Partition an integer x into n primes: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace, changed quotation(s) style.
m (→‎{{header|REXX}}: added/changed whitespace, changed quotation(s) style.)
Line 1,705:
<lang rexx>/*REXX program partitions integer(s) (greater than unity) into N primes. */
parse arg what /*obtain an optional list from the C.L.*/
 
do until what=='' /*possibly process a series of integers*/
parse var what x n what; parse var x x '-' y /*get possible range and # partitions.*/
Line 1,713 ⟶ 1,714:
if m=='' | m=="," then m= n /* " " " " " " */
call genP y /*generate Y number of primes. */
do g=x to y do g=x to y /*partition X ───► Y into partitions.*/
do q=n to m; call part do q=n to m; call part /* " G into Q primes. */
end /*q*/
end /*g*/
end /*until*/
 
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 1,726 ⟶ 1,728:
end /*k*/ /* [↓] a prime (J) has been found. */
#= # + 1; @.#= j /*bump prime count; assign prime to @.*/
end /*j*/; return
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
getP: procedure expose i. p. @.; parse arg z /*bump the prime in the partition list.*/
if i.z==0 then do; _= z - 1; i.z= i._; end
i.z= i.z + 1; _= i.z; p.z= @._; return 0
return 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
list: _= p.1; if $==g then do j=2 to q; _= _ p.j
end /*j*/
else _= '__(not_possible)'
return 'prime' || word('"s'", 1 + (q==1)) translate(_, "'+ "', '" _'") /*plural? */
/*──────────────────────────────────────────────────────────────────────────────────────*/
part: i.= 0; do j=1 for q; call getP j
end /*j*/
 
do !=0 by 0; $= 0 /*!: a DO variable for LEAVE & ITERATE*/
do s=1 for q; $= $ + p.s /* [↓] is sum of the primes too large?*/