From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.0 required=3.0 tests=BAYES_20,FREEMAIL_FROM, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:a37:2c45:0:b0:767:f1e8:d2d2 with SMTP id s66-20020a372c45000000b00767f1e8d2d2mr6264qkh.5.1690003845201; Fri, 21 Jul 2023 22:30:45 -0700 (PDT) X-Received: by 2002:a05:6808:2381:b0:3a3:c78e:d863 with SMTP id bp1-20020a056808238100b003a3c78ed863mr8907598oib.0.1690003844898; Fri, 21 Jul 2023 22:30:44 -0700 (PDT) Path: eternal-september.org!news.eternal-september.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 21 Jul 2023 22:30:44 -0700 (PDT) In-Reply-To: <1f6ad7f7-3bd3-4094-b037-eac7d352d68dn@googlegroups.com> Injection-Info: google-groups.googlegroups.com; posting-host=98.59.238.112; posting-account=oHOvdQoAAACYgyEBjgPNvKFOGxg8pNns NNTP-Posting-Host: 98.59.238.112 References: <1f6ad7f7-3bd3-4094-b037-eac7d352d68dn@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: memoization in Ada? Hash ADT? From: Kenneth Wolcott Injection-Date: Sat, 22 Jul 2023 05:30:45 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:65446 List-Id: On Friday, July 21, 2023 at 8:50:06=E2=80=AFPM UTC-7, Kenneth Wolcott wrote= : > Hi;=20 >=20 > I'm working on the Rosetta Code task:=20 >=20 > "Stirling numbers of the second kind"=20 >=20 > I have a working recursive solution written in Ada but I'd like to memoiz= e it to cut down on the redundant and duplicative calls (similar to a recur= sive solution to calculating the Fibonacci sequence).=20 >=20 > So I think I need a hash ADT (which I've used in Perl) but I've never use= d in Ada.=20 >=20 > So I want to preserve the calculation of the Stirling2 for each N and K s= o I can do a lookup. If this were based on a single unsigned integer, an ar= ray would suffice. Maybe a 2d array would suffice?=20 >=20 > Thanks,=20 > Ken Wolcott I solved the specific problem using a 2d array for caching. This is not me= moization, per se, but this works very well. The recursive calls are now v= ery 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 memoi= zation? Thanks, Ken