From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:aed:2725:: with SMTP id n34mr1626287qtd.333.1579059651083; Tue, 14 Jan 2020 19:40:51 -0800 (PST) X-Received: by 2002:a9d:53cb:: with SMTP id i11mr1334058oth.158.1579059650731; Tue, 14 Jan 2020 19:40:50 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no9936584qtd.0!news-out.google.com!w29ni1209qtc.0!nntp.google.com!g89no9936578qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 14 Jan 2020 19:40:50 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=50.66.161.135; posting-account=lzqe5AoAAADHhp_gregSufVhvwu22fBS NNTP-Posting-Host: 50.66.161.135 References: <3c6f1486-293d-4eb5-a379-279b108248d8@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Tally From: Brad Moore Injection-Date: Wed, 15 Jan 2020 03:40:51 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:57842 Date: 2020-01-14T19:40:50-08:00 List-Id: On Tuesday, January 14, 2020 at 2:08:16 PM UTC-7, Jeffrey R. Carter wrote: > A lot depends on what restraints the problem domain puts on the input val= ues. If=20 > you can define something like >=20 > type Input_Number is range 1 .. 10; >=20 > then you can do something straightforward like >=20 > type Count_Map is array (Input_Number) of Natural; >=20 > Count : Count_Map :=3D (others =3D> 0); > Number : Input_Number; > ... > loop > exit when No_More_Numbers; >=20 > Number :=3D Next_Number; > Count (Number) :=3D Count (Number) + 1; > end loop; >=20 > If you can't limit the input numbers to a sufficiently small range that a= n=20 > object like Count can be declared, then you'll need to use a map, as Hols= ti=20 > suggested, which is only a little more complicated. >=20 Just to clarify, I'd say using a Map is more complex (quite a bit actually)= in terms of what is happening semantically when the program executes, but = I think it is worth noting that there is not necessarily much difference in= complexity in terms of what the user has to write. As Jeff notes, using a = map does has the advantage of flexibility, for example in handling sparsely= populated data where there is a large range of input values. e.g. with Ada.Containers.Ordered_Maps; use Ada; procedure Main is package Count_Maps is new Containers.Ordered_Maps (Key_Type =3D> Natural, Element_Type =3D> Natural); =20 type Input_Data is array (Natural range <>) of Natural; =20 Input : Input_Data :=3D (2, 3, 8, 2, 2, 2, 7, 2, 3, 4, 8); =20 Counts : Count_Maps.Map; =20 begin for Number of Input loop Counts (Number) :=3D Counts (Number) + 1; end loop; end Main; Brad