On Friday, July 21, 2023 at 8:50:06 PM UTC-7, Kenneth Wolcott wrote:
Hi;
I'm working on the Rosetta Code task:
"Stirling numbers of the second kind"
I have a working recursive solution written in Ada but I'd like to memoize it to cut down on the redundant and duplicative calls (similar to a recursive solution to calculating the Fibonacci sequence).
So I think I need a hash ADT (which I've used in Perl) but I've never used in Ada.
So I want to preserve the calculation of the Stirling2 for each N and K so I can do a lookup. If this were based on a single unsigned integer, an array would suffice. Maybe a 2d array would suffice?
Thanks,
Ken Wolcott
I solved the specific problem using a 2d array for caching. This is not memoization, per se, but this works very well. The recursive calls are now very fast as there is a maximum of one calculation per recursive call.
So, any resources on how to write Ada programs that take advantage of memoization?
Thanks,
Ken
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)