From: Marius Amado Alves <amado.alves@netcabo.pt>
To: comp.lang.ada@ada-france.org
Subject: Re: Implementing Memorize
Date: Wed, 22 Oct 2003 12:29:08 +0000
Date: 2003-10-22T12:29:08+00:00 [thread overview]
Message-ID: <mailman.172.1066825790.25614.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <slrnbpcqnf.oa.lutz@taranis.iks-jena.de>
On Wed, 2003-10-22 at 11:33, Lutz Donnerhacke wrote:
> * Lutz Donnerhacke wrote:
> > Calculating Fibbonacci numbers recursivly is easy but braindead. Languages
> > with access to the symbol table at execution time are able to change the the
> > reccuring call with a memorize wrapper which returns already computed values
> > immediatly instead of recalculating them. In the referenced article I wrote
> > an C-Implementation of such a wrapper. Now I'm looking for a more elegant
> > version in Ada.
So your problem is generating the Fibonaci number of a given natural N.
I would not use recursive calls here because call stack space is usually
shorter than the range of naturals. I would use increments in a loop.
And I think I would use a precomputed table of values for N = 100,
200... (say). And it is clear that Fib (Natural'Last) is much bigger
than Natural'Last so I would look for the M such that Fib (M) <=
Natural'Last and Fib (M + 1) > Natural'Last and then constrain the input
type to 0 .. M. Or else use a big numbers package for the output type.
> ...
Took a look at your code. I think you're failing to set the Valid
component.
next prev parent reply other threads:[~2003-10-22 12:29 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-22 9:28 Implementing Memorize christoph.grein
2003-10-22 10:32 ` Lutz Donnerhacke
2003-10-22 10:48 ` Marius Amado Alves
2003-10-22 11:07 ` Lutz Donnerhacke
2003-10-22 11:33 ` Lutz Donnerhacke
2003-10-22 11:56 ` Lutz Donnerhacke
2003-10-22 12:29 ` Marius Amado Alves [this message]
2003-10-22 12:52 ` Lutz Donnerhacke
2003-10-22 13:42 ` Marius Amado Alves
2003-10-22 12:08 ` Dmitry A. Kazakov
2003-10-22 12:10 ` Lutz Donnerhacke
2003-10-22 15:23 ` Dmitry A. Kazakov
2003-10-22 19:41 ` Lutz Donnerhacke
2003-10-23 14:36 ` Dmitry A. Kazakov
2003-10-22 19:29 ` Robert I. Eachus
2003-10-22 19:44 ` Lutz Donnerhacke
-- strict thread matches above, loose matches on Subject: below --
2003-10-22 8:52 Lutz Donnerhacke
2003-10-22 15:00 ` Frank J. Lhota
2003-10-22 17:03 ` tmoran
2003-10-23 0:25 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox