Partition an integer x into n primes: Difference between revisions

m
→‎{{header|REXX}}: added usage comments to the REXX section header, changed REXX program to use a more idiomatic function name.
m (combined two bullets.)
m (→‎{{header|REXX}}: added usage comments to the REXX section header, changed REXX program to use a more idiomatic function name.)
Line 35:
 
=={{header|REXX}}==
Usage note:   entering ranges of   '''X'''   and   '''N'''   numbers (arguments) from the command line:
::::: &nbsp; <big> '''X-Y''' &nbsp; '''N-M''' &nbsp; &nbsp; <b> ∙∙∙ </b> </big>
 
which means: &nbsp; partition all integers (inclusive) from &nbsp; '''X''' ──► '''Y''' &nbsp; with &nbsp; '''N''' ──► '''M''' &nbsp; primes.
<br>The &nbsp; ''to'' &nbsp; number &nbsp; ('''Y''' &nbsp; or &nbsp; '''M''') &nbsp; can be omitted.
<lang rexx>/*REXX program partitions integer(s) (greater than unity) into N primes. */
parse arg what /*obtain an optional list from the C.L.*/
Line 64 ⟶ 69:
i.z=i.z+1; _=i.z; p.z=@._; return 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
lstlist: _=p.1; if $==g then do j=2 to q; _=_ p.j; end; else _= '__(not_possible)'; return _
ser: say; saythe= '***error*** primes:'; if arg(q==1); then the= 'prime: say'; return the translate(_,"+ ",' exit 13_')
/*──────────────────────────────────────────────────────────────────────────────────────*/
part: i.=0; do j=1 for q; call getP j; end /*j*/
Line 79 ⟶ 84:
if $ <g then do; call getP q; iterate; end
end /*!*/ /* [↑] Is sum too low? Bump a prime.*/
say 'partitioned' center(g,9) "into" center(q, 5)'primes:' translate(lst(),"+ ",' _' list()
return</lang>
{{out|output|text=&nbsp; when using the input of: &nbsp; <tt> 99809 1 &nbsp; 18 2 &nbsp; 19 3 &nbsp;20 4 &nbsp; 2017 24 &nbsp; 22699 1-4 &nbsp; 40355 </tt>