Anonymous user
Fractran: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, optimized a DO loop.
m (fixed HTML tag.) |
m (→{{header|REXX}}: added/changed comments and whitespace, optimized a DO loop.) |
||
Line 3,525:
numeric digits 2000 /*be able to handle larger numbers. */
parse arg N terms fracs /*obtain optional arguments from the CL*/
if N==''
if terms=='' | terms=="," then terms= 100 /* " " " " " " */
if fracs='' then fracs=
'77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1'
/* [↑] The default for the fractions. */
f= space(fracs, 0) /*remove all blanks from the FRACS list*/
do #=1 while f\==''; parse var f n.#
end /*#*/
#= # - 1 /*the number of fractions just found. */
say # 'fractions:' fracs /*display number and actual fractions. */
Line 3,538:
say terms ' terms are being shown:' /*display a kind of header/title. */
do
end
{{out|output|text= when using the default input:}}
<pre style="height:63ex">
Line 3,656:
Programming note: if the number of terms specified (the 2<sup>nd</sup> argument) is negative, then only powers of two are displayed.
<lang rexx>/*REXX program runs FRACTRAN for a given set of fractions and from a specified N. */
numeric digits 999; d=
parse arg N terms fracs /*obtain optional arguments from the CL*/
if N==''
if terms=='' | terms=="," then terms= 100 /* " " " " " " */
if fracs='' then fracs=
'77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1'
/* [↑] The default for the fractions. */
f= space(fracs, 0)
do #=1 while f\==''; parse var f n.#
end /*#*/
#= # - 1 /*adjust the number of fractions found.*/
tell= terms>0 /*flag: show number or a power of 2.*/
!.= 0; _= 1 /*the default value for powers of 2. */
if \tell then do p=1 until length(_)>
if p==1 then @._= left('', w + 9) "2**"left(p, w) ' '
else @._= '(prime' right(p, w)") 2**"left(p, w) ' '
Line 3,678:
if tell then say terms ' terms are being shown:' /*display header.*/
else say 'only powers of two are being shown:' /* " " */
q= '(max digits used:'
do j=1 for abs(terms) /*perform DO loop once for each term. */
else if !.N then say right('term' j,15) "──►" @.N q right(L,w)") " N
end
{{out|output|text= when using the input of: <tt> , -50000000 </tt>}}
<br>(negative fifty million)
|