Anonymous user
Partition an integer x into n primes: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace, changed quotation(s) style.
Alextretyak (talk | contribs) m (→{{header|11l}}) |
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. */
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
/*──────────────────────────────────────────────────────────────────────────────────────*/
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
/*──────────────────────────────────────────────────────────────────────────────────────*/
list: _= p.1; if $==g then do j=2 to q; _= _ p.j
end /*j*/
else _= '__(not_possible)'
return 'prime' || word(
/*──────────────────────────────────────────────────────────────────────────────────────*/
part: i.= 0;
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?*/
|