comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: creating an array
Date: Wed, 15 Feb 2006 00:10:42 +0100
Date: 2006-02-15T00:10:42+01:00	[thread overview]
Message-ID: <874q318rkd.fsf@ludovic-brenta.org> (raw)
In-Reply-To: 1139957691.430522.159580@o13g2000cwo.googlegroups.com

"isaac2004" <isaac_2004@yahoo.com> writes:

>>If I understand the problem correctly, what you want is:
>
> Inputs: 4 and 1977
> Output: 1779
>
>
> that is sort of correct but the code you just gave me just puts the
> array into a string and parses it out when the operation should be done
> on the array, i see that you can do it that way but that would make
> throw away all of my old code. how can the old code be changed,
> especially the procedure to split the file, so that i can preform these
> actions on an array

No, my program does not "put the array into a string".  It obtains
user input as a string (which is its natural form anyway), transforms
is into an array of Naturals, and then walks the array to display
sorted digits.  Your program takes the user input as a string (its
natural form), converts it to a number (by means of
Ada.Integer_Text_IO.Get), and then tries to massage it back into an
array.  This is not only convoluted, it is also inefficient.

If that's any help, you can convert a number to an array by working
backwards; units first, then tens, then hundreds etc.  This should get
you going:

type Index_Type is range 0 .. 9;
type Occurrences_Type is array (Index_Type) of Natural;

procedure Split (Number      : in     Natural;
                 Occurrences :    out Occurrences_Type) is
   Occurrences := (others => 0);
begin
   while Number > 0 loop
      Index := Index_Type (Number mod 10);
      Occurrences (Index) := Occurrences (Index) + 1;
      Number := Number / 10;
   end loop;
end Split;

But I still think my solution is much, much better :)

-- 
Ludovic Brenta.



  reply	other threads:[~2006-02-14 23:10 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-14  6:06 creating an array isaac2004
2006-02-14 13:59 ` jimmaureenrogers
2006-02-14 15:20   ` isaac2004
2006-02-14 18:44     ` jimmaureenrogers
2006-02-14 19:25 ` Björn Persson
2006-02-14 19:39   ` Dmitry A. Kazakov
2006-02-14 21:14     ` isaac2004
2006-02-14 22:17       ` jimmaureenrogers
2006-02-14 22:30         ` isaac2004
2006-02-14 22:45         ` Ludovic Brenta
2006-02-14 22:54           ` isaac2004
2006-02-14 23:10             ` Ludovic Brenta [this message]
2006-02-14 23:37               ` isaac2004
2006-02-15  7:45                 ` Anders Wirzenius
2006-02-15 20:44                   ` Björn Persson
2006-02-16  6:59                     ` Anders Wirzenius
2006-02-15 21:53                 ` Ludovic Brenta
2006-02-15 23:29                   ` isaac2004
2006-02-16  3:09                     ` jimmaureenrogers
2006-02-15  7:42     ` Maciej Sobczak
2006-02-15 10:37       ` Jean-Pierre Rosen
2006-02-15 13:30       ` Dmitry A. Kazakov
2006-02-15 16:23         ` isaac2004
replies disabled

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