Partition an integer x into n primes: Difference between revisions
Content added Content deleted
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: | Line 35: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Usage note: entering ranges of '''X''' and '''N''' numbers (arguments) from the command line: |
|||
::::: <big> '''X-Y''' '''N-M''' <b> ∙∙∙ </b> </big> |
|||
which means: partition all integers (inclusive) from '''X''' ──► '''Y''' with '''N''' ──► '''M''' primes. |
|||
<br>The ''to'' number ('''Y''' or '''M''') can be omitted. |
|||
<lang rexx>/*REXX program partitions integer(s) (greater than unity) into N primes. */ |
<lang rexx>/*REXX program partitions integer(s) (greater than unity) into N primes. */ |
||
parse arg what /*obtain an optional list from the C.L.*/ |
parse arg what /*obtain an optional list from the C.L.*/ |
||
Line 64: | Line 69: | ||
i.z=i.z+1; _=i.z; p.z=@._; return 0 |
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; else _= '__(not_possible)' |
|||
the= 'primes:'; if q==1 then the= 'prime: '; return the translate(_,"+ ",' _') |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
part: i.=0; do j=1 for q; call getP j; end /*j*/ |
part: i.=0; do j=1 for q; call getP j; end /*j*/ |
||
Line 79: | Line 84: | ||
if $ <g then do; call getP q; iterate; end |
if $ <g then do; call getP q; iterate; end |
||
end /*!*/ /* [↑] Is sum too low? Bump a prime.*/ |
end /*!*/ /* [↑] Is sum too low? Bump a prime.*/ |
||
say 'partitioned' center(g,9) "into" center(q,5) |
say 'partitioned' center(g,9) "into" center(q, 5) list() |
||
return</lang> |
return</lang> |
||
{{out|output|text= when using the input of: <tt> 99809 1 18 2 19 3 20 4 2017 24 22699 1-4 40355 </tt> |
{{out|output|text= when using the input of: <tt> 99809 1 18 2 19 3 20 4 2017 24 22699 1-4 40355 </tt> |