Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

memoization in Ada? Hash ADT?

81 views
Skip to first unread message

Kenneth Wolcott

unread,
Jul 21, 2023, 11:50:06 PM7/21/23
to
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

Kenneth Wolcott

unread,
Jul 22, 2023, 1:30:46 AM7/22/23
to
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

Gautier write-only address

unread,
Jul 24, 2023, 5:18:28 PM7/24/23
to
> So, any resources on how to write Ada programs that take advantage of memoization?

Look here https://forum.ada-lang.io/ for discussions about Advent of Code puzzles. Some solutions use (and need, for completing in a reasonable time) memoization.
You find with HAC ( https://hacadacompiler.sourceforge.io/ ) a set of solutions (search "memoiz*" or "cache"), mostly compiling with the HAC subset.

Kenneth Wolcott

unread,
Jul 26, 2023, 12:38:04 AM7/26/23
to
Thanks for the pointer to the forum.

Regarding HAC, isn't that Windows-only? I'm on a Mac (M1 chip). I'll look again at HAC.

Ken

Simon Wright

unread,
Jul 26, 2023, 3:50:05 AM7/26/23
to
Kenneth Wolcott <kenneth...@gmail.com> writes:

> Regarding HAC, isn't that Windows-only? I'm on a Mac (M1 chip). I'll
> look again at HAC.

It worked well enough for me to find a failing test case (now fixed!)

Gautier write-only address

unread,
Jul 26, 2023, 5:36:17 PM7/26/23
to
> Regarding HAC, isn't that Windows-only?

Not at all :-)

Kenneth Wolcott

unread,
Jul 26, 2023, 6:18:54 PM7/26/23
to
On Wednesday, July 26, 2023 at 2:36:17 PM UTC-7, Gautier write-only address wrote:
> > Regarding HAC, isn't that Windows-only?
> Not at all :-)

Downloaded and ran demo. Will experiment further as time permits. Nice!

Thanks,
Ken
0 new messages