2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,23 +1,23 @@
/*REXX program calculates the Nth Fibonacci number, N can be zero or neg*/
numeric digits 210000 /*be able to handle some big 'uns*/
parse arg x y . /*allow a single number or range.*/
if x=='' then do; x=-40; y=+40; end /*No input? Use range -40 ──► +40*/
if y=='' then y=x /*if only one number, show fib(n)*/
w=max(length(x), length(y)) /*used for making output pretty. */
fw=10 /*minmum maximum width. Ka-razy.*/
do j=x to y; q=fib(j) /*process each Fibonacci request.*/
L=length(q) /*obtain the length (width) of Q.*/
fw=max(fw, L) /*fib# length or the max so far. */
say 'Fibonacci('right(j,w)") = " right(q,fw) /*right justify Q.*/
if L>10 then say 'Fibonacci('right(j,w)") has a length of" L
end /*j*/ /* [↑] list a Fib seq. of x──►y */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────FIB subroutine──────────────────────*/
fib: procedure; parse arg n; a=0; b=1; na=abs(n) /*use |n| */
if na<2 then return na /*handle 3 special cases (-1,0,1)*/
/* [↓] method is non-recursive.*/
do k=2 to na; s=a+b; a=b; b=s /*sum the numbers up to │n│ */
end /*k*/ /* [↑] (only positive Fibs used)*/
/* [↓] na//2 [same as] na/2==1 */
if n>0 | na//2 then return s /*if positive or odd negative ···*/
return -s /*return a negative Fib number. */
/*REXX program calculates the Nth Fibonacci number, N can be zero or negative. */
numeric digits 210000 /*be able to handle ginormous numbers. */
parse arg x y . /*allow a single number or a range. */
if x=='' | x=="," then do; x=-40; y=+40; end /*No input? Then use range -40 ──► +40*/
if y=='' | y=="," then y=x /*if only one number, display fib(X).*/
w=max(length(x), length(y) ) /*W: used for making formatted output.*/
fw=10 /*Minimum maximum width. Sounds ka─razy*/
do j=x to y; q=fib(j) /*process all of the Fibonacci requests*/
L=length(q) /*obtain the length (decimal digs) of Q*/
fw=max(fw, L) /*fib number length, or the max so far.*/
say 'Fibonacci('right(j,w)") = " right(q,fw) /*right justify Q*/
if L>10 then say 'Fibonacci('right(j, w)") has a length of" L
end /*j*/ /* [↑] list a Fib. sequence of x──►y */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
fib: procedure; parse arg n; an=abs(n) /*use │n│ (the absolute value of N).*/
a=0; b=1; if an<2 then return an /*handle two special cases: zero & one.*/
/* [↓] this method is non─recursive. */
do k=2 to an; $=a+b; a=b; b=$ /*sum the numbers up to │n│ */
end /*k*/ /* [↑] (only positive Fibs nums used).*/
/* [↓] an//2 [same as] (an//2==1).*/
if n>0 | an//2 then return $ /*Positive or even? Then return sum. */
return -$ /*Negative and odd? Return negative sum*/