From: brianc@billybob.demon.co.uk (Brian A Crawford)
Subject: Two Dimensional Array
Date: Fri, 15 Feb 2002 12:30:42 GMT
Date: 2002-02-15T12:30:42+00:00 [thread overview]
Message-ID: <3c6cf3db.11214605@news.demon.co.uk> (raw)
I have a program to read two numbers at a time from a file and then
use a two dimensional array to look at that reference to see if a
number 1 or 0 in assigned to the cell referenced.
For example if the numbers are 14,20 it would look up this in the
array and return a 1 say.
I have already got it to work (see fragment below) however the real
world problem is that the numbers 1 to 50 are not actually in
numerical order but jumbled up in a different sequence.
The code fragment shows the end result of my efforts so far.
My problem is associating the values 1 or 0 to each cell of the array.
By having the numbers 1 to 50 in numerical order the numbers 1 and 0
are very haphazard placed and are difficult to define and update.
If the array was firstly defined as say 1,21,34,50,17,4, etc, 48,16
then the 1 and 0 are placed together in the array and are very easy to
associate quickly in groups of 5.
Example
Event := (1 => (1,1,1,1,1,0,0,0,0,0,1,1,1,1,1 etc
21 => (0,0,0,0,0,1,1,1,1,1,0,0,0,0,0, etc
34 => (0,0,0,0,0,0,0,0,0,0,1,1,1,1,1, etc
and so on.
This is a code fragment.
Number1 : Integer;
Number2 : Integer;
subtype Firstevent is Integer range 1..50;
subtype Secondevent is Integer range 1..50;
type Two_Events_Type is array (Firstevent, Secondevent) of
Integer;
Event : Two_Events_Type;
begin
--get input data
Event := (0 =>
(1,0,0,1,0,1,1,0,0,0,0,1,1,0,1,1,1,0,1,etc,0,1,0,1,1,1,0,0,1,1),
1=>(1,1,0,1,0,0,1,0,0,1,1,1,etc
2=> and so forth
as you can see the 1's and 0's are all over the place.
How can I define subtypes FirstEvent and SecondEvent out of sequence?
Secondly then can I make an abbreviation to the array referencing eg
if AN is the sequence of 5 x 1's at {3,4,5,6,7} and BN is is the
sequence of 5 x 1's at {17,18,19,20,21} position and similar for CN DN
EN etc how may I use that abbreviation in some way like this?
Event := (0 => (AN, BN, others => 0),
21 => (CN, others =>0),
34 => (DN, AN, CN, others 0)) etc
Thank you for any pointers.
Regards
Brian
next reply other threads:[~2002-02-15 12:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-15 12:30 Brian A Crawford [this message]
2002-02-15 17:28 ` Two Dimensional Array Jeffrey Carter
2002-02-15 18:15 ` Stephen Leake
2002-02-15 22:50 ` Brian A Crawford
2002-02-16 2:05 ` Mike Silva
2002-02-16 9:38 ` Brian A Crawford
2002-02-23 13:36 ` Nick Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox