|A little HP-71B challenge|
Message #1 Posted by Ex-PPC member on 14 Feb 2003, 8:31 a.m.
As most of you already know, the HP-71B features an
extremely powerful version of BASIC, which among other
things, allows recursion, i.e.: a function or subprogram
may call itself.
This makes it pretty easy to write a recursive, multiline
user-defined function to compute, say, the factorial function:
n! = 1 x 2 x 3 x ... x (n-1) x n
like this one, for instance, valid for integer N greater than 0:
10 DEF FNF(N)
20 IF N=1 THEN FNF=1 ELSE FNF=N*FNF(N-1)
30 END DEF
As you can see, thanks to recursion it's really easy
(if inefficient) to do it using a multiline user-defined
The challenge is: try and define a factorial function as
above, but using a single-line, single-statement user
By single-line, single-statement I mean your function
must be defined like this:
10 DEF FNF(N)= ...
and it must be recursive, i.e: it must call itself. No
"END DEF" nor "@" (statement concatenators) are allowed,
nor can you invoke another user-defined function.
Give it yourself a try before looking elsewhere. Once you
succeed, this will be a pretty confirmation that single-line user-defined functions can be recursive as well on 71B's