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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1e40bdb19094c551 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.235.4 with SMTP id ui4mr266263pbc.3.1333569632401; Wed, 04 Apr 2012 13:00:32 -0700 (PDT) Path: r9ni18735pbh.0!nntp.google.com!news2.google.com!news4.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Array/Matrix Help Date: Wed, 04 Apr 2012 23:00:31 +0300 Organization: Tidorum Ltd Message-ID: <9u3nivFq18U1@mid.individual.net> References: Mime-Version: 1.0 X-Trace: individual.net G3tMeSen+17SRuS/1p/dDQ4PFkUUZyfnwL2KVOW556poxxp9T1 Cancel-Lock: sha1:BSM7Iktr1oeXgVD/SqP+wM/D4co= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:11.0) Gecko/20120313 Thunderbird/11.0 In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-04-04T23:00:31+03:00 List-Id: On 12-04-04 05:55 , Will wrote: > I need to create function Create_Matrix that accepts four > Int_Arrays. It must determine if all 4 Int_Arrays are of equal length > and then creates and returns an Int_Matrix of the 2 or more arrays > with equal length. > > Here is what I am thinking so far, I believe it will work but seems > inefficient and I am looking for efficiency in my coding. I am not > sure how to determine which ones are equal other than a bunch of if/ > elsif statement that cover every possible combination of them being > equal then write the code that will create the matrix for that given > combination of arrays. Any ideas on something better than the > following. I am assuming that there will not be 2 sets of arrays that > are equal (i.e. 2 arrays of length 5 , and another 2 of length 7) > There would only be 1 common length. > > function Create_Matrix (A, B, C, D : Int_Array) return Int_Matrix > > begin > > if A'Length = B'Length and A'Length = C'Length and A'Length > = D'Length then > > Then continue to do this all the way until I cover every combination > of 2 or more arrays that are equal length and then whichever if > statement it satisfies create the Int_Matrix by each array being its > own line inside the matrix. > > Can anyone offer help or ideas. Any hints/help is greatly > appreciated... I prefer that over just giving me the code. I always prefer systematic coding over efficiency. Here is what I would do. Put the four lengths into a 4-element array: Length : constant array (1 .. 4) of Natural := ( A'Length, B'Length, C'Length, D'Length); Then make another array that counts how many times each length occurs: Occurrences : array (1 .. 4) of Natural := (others => 0); for I in 1 .. 4 loop for J in 1 .. 4 loop if Length(J) = Length(I) then Occurrences(I) := Occurrences(I) + 1; end if; end loop; end loop; Then find a maximal element of Occurrences, say Occurrences(K), and make a matrix of all the input vectors that have the length Length(K). (Finding a maximal value can be combined with the loops that compute Occurrences, of course.) HTH, -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .