RosettaCodeData/Task/Fibonacci-sequence/NetRexx/fibonacci-sequence.netrexx

38 lines
1.1 KiB
Plaintext

/* NetRexx */
options replace format comments java crossref savelog symbols
numeric digits 210000 /*prepare for some big 'uns. */
parse arg x y . /*allow a single number or range.*/
if x == '' then do /*no input? Then assume -30-->+30*/
x = -30
y = -x
end
if y == '' then y = x /*if only one number, show fib(n)*/
loop k = x to y /*process each Fibonacci request.*/
q = fib(k)
w = q.length /*if wider than 25 bytes, tell it*/
say 'Fibonacci' k"="q
if w > 25 then say 'Fibonacci' k "has a length of" w
end k
exit
/*-------------------------------------FIB subroutine (non-recursive)---*/
method fib(arg) private static
parse arg n
na = n.abs
if na < 2 then return na /*handle special cases. */
a = 0
b = 1
loop j = 2 to na
s = a + b
a = b
b = s
end j
if n > 0 | na // 2 == 1 then return s /*if positive or odd negative... */
else return -s /*return a negative Fib number. */