Tuesday, October 21, 2008

memoized factorial for bc

bc on solaris craps out with recursion when the level's over 48


define f(x) {
if (x>1) {
if (f[x]) {
return (f[x])
}
f[x] = (x * f(x-1))
return (f[x])
}
return (1)
}


memoization partly fixes the annoyance.

No comments: