[Shootout-list] fibonacci and ackermann

Sebastien Loisel Sebastien Loisel <sloisel@gmail.com>
Sun, 3 Apr 2005 21:51:34 +0200


> Any time you use a function with the same input more than once,
> there's a chance for memoization. Why not just use a function that
> uses each input only once.

Good plan, but

> proc Nsum {n} {
>     expr { $n + [Nsum [incr n -1]] }
> }

a smart compiler might be able to loopify this one, like tail
recursion. If not, anyone could rewrite it in the tail recursive idiom
of the language, which would be legitimate but would cause the
compiler to remove the recursion.

Ackermann is a *lot* of recursion, but it has the advantage of being
very nontrivial to optimize away. If you can figure out a recursive
function that doesn't optimize away, that would be cool too.

Sebastien Loisel