From: Adam Beneschan <adam@irvine.com>
Subject: Re: Array/Matrix Help
Date: Wed, 4 Apr 2012 09:20:22 -0700 (PDT)
Date: 2012-04-04T09:20:22-07:00 [thread overview]
Message-ID: <4668787.390.1333556422640.JavaMail.geo-discussion-forums@ynib40> (raw)
In-Reply-To: <eef91ea3-652f-47e4-8de2-f26a3d8ae1ce@f6g2000vbc.googlegroups.com>
On Tuesday, April 3, 2012 7:55:26 PM UTC-7, 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 don't think there's a good way to do this except with a bunch of if/then/elses. If you're super-concerned about efficiency, you might want to create a 6-bit integer where each bit corresponds to one of the six pairs of comparisons (add 1 if A'Length=B'Length, add 2 if A'Length=C'Length, add 4 if something...) and then do a CASE on the integer to cover all 64 possibilities. But that's an ugly way to write this just to eliminate a few nanoseconds.
-- Adam
next prev parent reply other threads:[~2012-04-04 16:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-04 2:55 Array/Matrix Help Will
2012-04-04 16:20 ` Adam Beneschan [this message]
2012-04-04 20:00 ` Niklas Holsti
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox