Re: Dynamic matrix in Euphoria

new topic     » goto parent     » topic index » view thread      » older message » newer message

Allen V Robnett wrote:
> 
> Given a series of sets containing a variable number of items (say n 
> items), is it possible to have Euphoria define a square matrix 
> dynamically, n by n, assigning the nth row and the nth column to the nth 
> item of the current set, or would it be necessary to define the matrix 
> in advance, hoping that the chosen value of n would be large enough to 
> accommodate all possible cases?

That is one of the strong points of Euphoria, you can create sequences 
of as many dimensions as you wish, they are automatically managed. 
How to create them most easily is the only concern.

For example, a square matrix, 4x4, could be created manually:
sequence x
 x = {{0,1,2,3},
      {5,10,15,20},
      {0,0,0,0},
      {0,0,0,0}} 

alternatively, you could create it using: 
constant n = 4
sequence a
   a = repeat(0,n) 
   x = repeat(a,n) 

You can also create variable sizes:
x = {{1,2,3},
     {4,5,6,7,8,9},
     {10},
     {}}

Where ? x[1][3] returns 3
      ? x[3][1] returns 10
      ? x[4] returns {}
      ? x[2][4] returns 7
      and ? x[2] returns {4,5,6,7,8,9}

Regards,
Irv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu