comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Tally
Date: Tue, 14 Jan 2020 22:08:07 +0100
Date: 2020-01-14T22:08:07+01:00	[thread overview]
Message-ID: <qvlajt$95j$1@dont-email.me> (raw)
In-Reply-To: <3c6f1486-293d-4eb5-a379-279b108248d8@googlegroups.com>

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

  parent reply	other threads:[~2020-01-14 21:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-14 15:27 Tally Gilbert Gosseyn
2020-01-14 16:22 ` Tally Niklas Holsti
2020-01-14 17:28   ` Tally Simon Wright
2020-01-15 11:52     ` Tally Simon Wright
2020-01-14 21:08 ` Jeffrey R. Carter [this message]
2020-01-15  3:40   ` Tally Brad Moore
2020-01-15  9:03     ` Tally Simon Wright
2020-01-15 23:09       ` Tally Jere
2020-01-16 11:34         ` Tally Simon Wright
2020-01-16 15:35           ` Tally Brad Moore
2020-01-16 20:20             ` Tally Randy Brukardt
2020-01-16 22:03               ` Tally Jeffrey R. Carter
2020-01-16 22:00             ` Tally Jeffrey R. Carter
2020-01-16 22:25               ` Tally Simon Wright
2020-01-17  2:51                 ` Tally Brad Moore
2020-01-17  3:08       ` Tally Brad Moore
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox