SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    525
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Three Dimensional Array Calculation/Formula

    i'm needing to calculate how many elements are remaining in an array from a particular point. i figured out a way to do this with a two dimensional array:

    Code:
    0,0     0,1     0,2
    1,0     1,1    1,2
    2,0     2,1     2,2(a)
    
     2,2
    -0,1
    -----
    2(b),1(c)
    
    2(b) * (2(a) + 1) = 6(d)
    
    6(d) + 1(c) = 7
    
    so 7 spots from 0,1 to 2,2.

    i can't figure out a formula that would work for 3+ dimensional arrays, however.

    Code:
    0,0,0     0,0,1     0,0,2     0,0,3
    0,1,0     0,1,1     0,1,2     0,1,3
    1,0,0     1,1,1     1,1,2     1,1,3
    say from 0,0,2 to 1,1,3 - for example.

    any suggestions? i'm assuming there's a formula out there somewhere, i just don't know what it is.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I posted a working formula in your other post.

  3. #3
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    525
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i just figured one out, and it's pretty similar...

    Code:
    2(a), 2(b), 3(c)
    0(x), 1(y), 0(z)
    
     ((b * c) * ((a - 1) - x)) + (c * (b - 1) - y) + (c - 1) - z = n
    
    so....
    
    ((2 * 3) * ((2 - 1) - 0)) + (3 * (2 - 1) - 1) + (3 - 1) - 0 = n
       ( 6    *        1)        +       0        +             2      = 8


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •