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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Tally Date: Tue, 14 Jan 2020 22:08:07 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <3c6f1486-293d-4eb5-a379-279b108248d8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 14 Jan 2020 21:08:14 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="1aedcaba92352d87484a2ddbfaf81201"; logging-data="9395"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hRoj4qqUzpMWyihlH1qhuzhk3VtVJows=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 Cancel-Lock: sha1:8nPdHOUt7Lfq/4AvEzM0tKJzfeo= In-Reply-To: <3c6f1486-293d-4eb5-a379-279b108248d8@googlegroups.com> Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57841 Date: 2020-01-14T22:08:07+01:00 List-Id: On 1/14/20 4:27 PM, Gilbert Gosseyn wrote: > Before I make long tests with access Types, declarations or containers, I would like to get an advice on how to program in a simple and fast way the following, or get a hint to an existing program. > > Example_Input: (2, 3, 8, 2, 2, 2, 7, 2, 3, 4, 8) ; -- variable Length > > Output by function or procedure : ((2, 5), (3, 2), (8, 2), (7, 1), (4, 1)); -- unknown Length A lot depends on what restraints the problem domain puts on the input values. If you can define something like type Input_Number is range 1 .. 10; then you can do something straightforward like type Count_Map is array (Input_Number) of Natural; Count : Count_Map := (others => 0); Number : Input_Number; ... loop exit when No_More_Numbers; Number := Next_Number; Count (Number) := Count (Number) + 1; end loop; If you can't limit the input numbers to a sufficiently small range that an object like Count can be declared, then you'll need to use a map, as Holsti suggested, which is only a little more complicated. -- Jeff Carter Just as Khan was hindered by two-dimensional thinking in a three-dimensional situation, so many developers are hindered by sequential thinking in concurrent situations. 118