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

@ -0,0 +1,13 @@
/*REXX program to show anonymous recursion (of a function or subroutine). */
numeric digits 1e6 /*in case the user goes ka-razy. */
parse arg x . /*obtain the optional argument from CL.*/
if x=='' | x=="," then x=12 /*Not specified? Then use the default.*/
w=length(x) /*W: used for formatting the output. */
do j=0 to x; jj=right(j, w) /*use the argument as an upper limit.*/
say 'fibonacci('jj") =" fib(j) /*show the Fibonacci sequence: 0 ──► x */
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
fib: procedure; parse arg z; if z>=0 then return .(z)
say "***error*** argument can't be negative."; exit
.: procedure; parse arg #; if #<2 then return #; return .(#-1) + .(#-2)

View file

@ -0,0 +1,14 @@
/*REXX program to show anonymous recursion of a function or subroutine with memoization.*/
numeric digits 1e6 /*in case the user goes ka-razy. */
parse arg x . /*obtain the optional argument from CL.*/
if x=='' | x=="," then x=12 /*Not specified? Then use the default.*/
@.=.; @.0=0; @.1=1 /*used to implement memoization for FIB*/
w=length(x) /*W: used for formatting the output. */
do j=0 to x; jj=right(j, w) /*use the argument as an upper limit.*/
say 'fibonacci('jj") =" fib(j) /*show the Fibonacci sequence: 0 ──► x */
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
fib: procedure expose @.; arg z; if z>=0 then return .(z)
say "***error*** argument can't be negative."; exit
.: procedure expose @.; arg #; if @.#\==. then return @.#; @.#=.(#-1)+.(#-2); return @.#

View file

@ -1,11 +0,0 @@
/*REXX program to show anonymous recursion (of a function/subroutine). */
numeric digits 1e6 /*in case the user goes kaa-razy.*/
do j=0 to word(arg(1) 12, 1) /*use argument or the default: 12*/
say 'fibonacci('j") =" fib(j) /*show Fibonacci sequence: 0──►x */
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────subroutines─────────────────────────*/
fib: procedure; if arg(1)>=0 then return .(arg(1))
say "***error!*** argument can't be negative."; exit
.:procedure; arg _; if _<2 then return _; return .(_-1)+.(_-2)