Position item in an array larger than 3D

General FreeBASIC programming questions.
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » May 16, 2012 19:01

@ fxm:

Because there is this difference between FreeBASIC and the mathematical formula of 1 element?
fxm
Posts: 8957
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Position item in an array larger than 3D

Postby fxm » May 16, 2012 19:39

lrcvs wrote:@ fxm:

Because there is this difference between FreeBASIC and the mathematical formula of 1 element?

It is just a problem of notation:
We can consider that:
offset = position - 1
or
position = offset + 1

Offset represents the address difference between the address of an element and the address (beginning) of the allocated memory block:
- the first element (position 1) is put in memory at the offset = 0 (top of memory block)
- the second element (position 2) is put in memory at the offset = 1 (top of memory block + 1)
- the third element (position 3) is put in memory at the offset = 2 (top of memory block + 2)
- and so on...

Code: Select all

             -----------------------
Address X   : element in position 1 : Offset 0
            :-----------------------:
Address X+1 : element in position 2 : Offset 1
            :-----------------------:
Address X+2 : element in position 3 : Offset 2
            :-----------------------:
..............................................
..............................................
Last edited by fxm on May 23, 2015 6:25, edited 1 time in total.
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » May 16, 2012 21:05

Ok., thanks!
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » May 23, 2015 5:55

Hi:

After three years ...

To use it?

What use is?

Has anyone tried to use this in reverse?

For example:
There are 3 sets of 27 elements each (3 * 3 * 3).
Total of 81 elements. (27 * 3 = 81)

question:
The element 68, where it is?

answer:
Row = 2
Col = 2
Level = 2
Dimension = 3

As you have done?

regards
fxm
Posts: 8957
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Position item in an array larger than 3D

Postby fxm » May 23, 2015 6:35

Yes:

Code: Select all

Dim As Byte array(1 To 27, 1 To 3, 1 To 3, 1 To 3)
Print @array(3, 2, 2, 2) - @array(1, 1, 1, 1) + 1
Sleep

Code: Select all

 68

Code: Select all

Dim As Byte array(1 To 27, 1 To 3, 1 To 3, 1 To 3)

Dim As Integer I, J, K, L
For I = Lbound(array, 1) To Ubound(array, 1)
  For J = Lbound(array, 2) To Ubound(array, 2)
    For K = Lbound(array, 3) To Ubound(array, 3)
      For L = Lbound(array, 4) To Ubound(array, 4)
        If @array(I, J, K, L) - @array(Lbound(array, 1), Lbound(array, 2), Lbound(array, 3), Lbound(array, 4)) + 1 = 68 Then
          Exit For, For, For, For
        End If
      Next L
    Next K
  Next J
Next I

Print I; J; K; L
Sleep

Code: Select all

 3 2 2 2
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » May 23, 2015 9:14

Hi, fmx:

It's very good!

Post error, deleted!!
The notified: 25.05.15
By: lrcvs
Last edited by lrcvs on May 24, 2015 23:40, edited 3 times in total.
stylin
Posts: 1253
Joined: Nov 06, 2005 5:19

Re: Position item in an array larger than 3D

Postby stylin » May 23, 2015 13:36

[code=vbnet file=Untitled.bas]scope
const XSIZE = 3
const YSIZE = 2, YPITCH = XSIZE

dim array(YSIZE-1, XSIZE-1) as integer => {{0,1,2},{3,4,5}}

print "2 dimensions:"
for i as integer = 0 to YSIZE*XSIZE - 1
var y = (i ) \ YPITCH
var x = (i - y*YPITCH)
print using "i:# y:# x:# array(y,x):#"; i; y; x; array(y, x)
next i
print
end scope

scope
const XSIZE = 4
const YSIZE = 3, YPITCH = XSIZE
const ZSIZE = 2, ZPITCH = XSIZE*YSIZE

dim array(ZSIZE-1, YSIZE-1, XSIZE-1) as integer => _
{{{ 0, 1, 2, 3},{ 4, 5, 6, 7},{ 8, 9,10,11}}, _
{{12,13,14,15},{16,17,18,19},{20,21,22,23}}}

print "3 dimensions:"
for i as integer = 0 to ZSIZE*YSIZE*XSIZE - 1
var z = (i ) \ ZPITCH
var y = (i - z*ZPITCH ) \ YPITCH
var x = (i - z*ZPITCH - y*YPITCH)
print using "i:## z:# y:# x:# array(z,y,x):##"; i; z; y; x; array(z, y, x)
next i
print
end scope

scope
const XSIZE = 5
const YSIZE = 4, YPITCH = XSIZE
const ZSIZE = 3, ZPITCH = XSIZE*YSIZE
const WSIZE = 2, WPITCH = XSIZE*YSIZE*ZSIZE

dim array(WSIZE-1, ZSIZE-1, YSIZE-1, XSIZE-1) as integer => _
{{{{ 0, 1, 2, 3, 4},{ 5, 6, 7, 8, 9},{ 10, 11, 12, 13, 14},{ 15, 16, 17, 18, 19}}, _
{{ 20, 21, 22, 23, 24},{ 25, 26, 27, 28, 29},{ 30, 31, 32, 33, 34},{ 35, 36, 37, 38, 39}}, _
{{ 40, 41, 42, 43, 44},{ 45, 46, 47, 48, 49},{ 50, 51, 52, 53, 54},{ 55, 56, 57, 58, 59}}}, _
{{{ 60, 61, 62, 63, 64},{ 65, 66, 67, 68, 69},{ 70, 71, 72, 73, 74},{ 75, 76, 77, 78, 79}}, _
{{ 80, 81, 82, 83, 84},{ 85, 86, 87, 88, 89},{ 90, 91, 92, 93, 94},{ 95, 96, 97, 98, 99}}, _
{{100,101,102,103,104},{105,106,107,108,109},{110,111,112,113,114},{115,116,117,118,119}}}}

print "4 dimensions:"
for i as integer = 0 to WSIZE*ZSIZE*YSIZE*XSIZE - 1
var w = (i ) \ WPITCH
var z = (i - w*WPITCH ) \ ZPITCH
var y = (i - w*WPITCH - z*ZPITCH ) \ YPITCH
var x = (i - w*WPITCH - z*ZPITCH - y*YPITCH)
print using "i:### w:# z:# y:# x:# array(w,z,y,x):###"; i; w; z; y; x; array(w, z, y, x)
next i
end scope
[/code]

[code=text file=Untitled.bas]2 dimensions:
i:0 y:0 x:0 array(y,x):0
i:1 y:0 x:1 array(y,x):1
i:2 y:0 x:2 array(y,x):2
i:3 y:1 x:0 array(y,x):3
i:4 y:1 x:1 array(y,x):4
i:5 y:1 x:2 array(y,x):5

3 dimensions:
i: 0 z:0 y:0 x:0 array(z,y,x): 0
i: 1 z:0 y:0 x:1 array(z,y,x): 1
i: 2 z:0 y:0 x:2 array(z,y,x): 2
i: 3 z:0 y:0 x:3 array(z,y,x): 3
i: 4 z:0 y:1 x:0 array(z,y,x): 4
i: 5 z:0 y:1 x:1 array(z,y,x): 5
i: 6 z:0 y:1 x:2 array(z,y,x): 6
i: 7 z:0 y:1 x:3 array(z,y,x): 7
i: 8 z:0 y:2 x:0 array(z,y,x): 8
i: 9 z:0 y:2 x:1 array(z,y,x): 9
i:10 z:0 y:2 x:2 array(z,y,x):10
i:11 z:0 y:2 x:3 array(z,y,x):11
i:12 z:1 y:0 x:0 array(z,y,x):12
i:13 z:1 y:0 x:1 array(z,y,x):13
i:14 z:1 y:0 x:2 array(z,y,x):14
i:15 z:1 y:0 x:3 array(z,y,x):15
i:16 z:1 y:1 x:0 array(z,y,x):16
i:17 z:1 y:1 x:1 array(z,y,x):17
i:18 z:1 y:1 x:2 array(z,y,x):18
i:19 z:1 y:1 x:3 array(z,y,x):19
i:20 z:1 y:2 x:0 array(z,y,x):20
i:21 z:1 y:2 x:1 array(z,y,x):21
i:22 z:1 y:2 x:2 array(z,y,x):22
i:23 z:1 y:2 x:3 array(z,y,x):23

4 dimensions:
i: 0 w:0 z:0 y:0 x:0 array(w,z,y,x): 0
i: 1 w:0 z:0 y:0 x:1 array(w,z,y,x): 1
i: 2 w:0 z:0 y:0 x:2 array(w,z,y,x): 2
i: 3 w:0 z:0 y:0 x:3 array(w,z,y,x): 3
i: 4 w:0 z:0 y:0 x:4 array(w,z,y,x): 4
i: 5 w:0 z:0 y:1 x:0 array(w,z,y,x): 5
i: 6 w:0 z:0 y:1 x:1 array(w,z,y,x): 6
i: 7 w:0 z:0 y:1 x:2 array(w,z,y,x): 7
i: 8 w:0 z:0 y:1 x:3 array(w,z,y,x): 8
i: 9 w:0 z:0 y:1 x:4 array(w,z,y,x): 9
i: 10 w:0 z:0 y:2 x:0 array(w,z,y,x): 10
i: 11 w:0 z:0 y:2 x:1 array(w,z,y,x): 11
i: 12 w:0 z:0 y:2 x:2 array(w,z,y,x): 12
i: 13 w:0 z:0 y:2 x:3 array(w,z,y,x): 13
i: 14 w:0 z:0 y:2 x:4 array(w,z,y,x): 14
i: 15 w:0 z:0 y:3 x:0 array(w,z,y,x): 15
i: 16 w:0 z:0 y:3 x:1 array(w,z,y,x): 16
i: 17 w:0 z:0 y:3 x:2 array(w,z,y,x): 17
i: 18 w:0 z:0 y:3 x:3 array(w,z,y,x): 18
i: 19 w:0 z:0 y:3 x:4 array(w,z,y,x): 19
i: 20 w:0 z:1 y:0 x:0 array(w,z,y,x): 20
i: 21 w:0 z:1 y:0 x:1 array(w,z,y,x): 21
i: 22 w:0 z:1 y:0 x:2 array(w,z,y,x): 22
i: 23 w:0 z:1 y:0 x:3 array(w,z,y,x): 23
i: 24 w:0 z:1 y:0 x:4 array(w,z,y,x): 24
i: 25 w:0 z:1 y:1 x:0 array(w,z,y,x): 25
i: 26 w:0 z:1 y:1 x:1 array(w,z,y,x): 26
i: 27 w:0 z:1 y:1 x:2 array(w,z,y,x): 27
i: 28 w:0 z:1 y:1 x:3 array(w,z,y,x): 28
i: 29 w:0 z:1 y:1 x:4 array(w,z,y,x): 29
i: 30 w:0 z:1 y:2 x:0 array(w,z,y,x): 30
i: 31 w:0 z:1 y:2 x:1 array(w,z,y,x): 31
i: 32 w:0 z:1 y:2 x:2 array(w,z,y,x): 32
i: 33 w:0 z:1 y:2 x:3 array(w,z,y,x): 33
i: 34 w:0 z:1 y:2 x:4 array(w,z,y,x): 34
i: 35 w:0 z:1 y:3 x:0 array(w,z,y,x): 35
i: 36 w:0 z:1 y:3 x:1 array(w,z,y,x): 36
i: 37 w:0 z:1 y:3 x:2 array(w,z,y,x): 37
i: 38 w:0 z:1 y:3 x:3 array(w,z,y,x): 38
i: 39 w:0 z:1 y:3 x:4 array(w,z,y,x): 39
i: 40 w:0 z:2 y:0 x:0 array(w,z,y,x): 40
i: 41 w:0 z:2 y:0 x:1 array(w,z,y,x): 41
i: 42 w:0 z:2 y:0 x:2 array(w,z,y,x): 42
i: 43 w:0 z:2 y:0 x:3 array(w,z,y,x): 43
i: 44 w:0 z:2 y:0 x:4 array(w,z,y,x): 44
i: 45 w:0 z:2 y:1 x:0 array(w,z,y,x): 45
i: 46 w:0 z:2 y:1 x:1 array(w,z,y,x): 46
i: 47 w:0 z:2 y:1 x:2 array(w,z,y,x): 47
i: 48 w:0 z:2 y:1 x:3 array(w,z,y,x): 48
i: 49 w:0 z:2 y:1 x:4 array(w,z,y,x): 49
i: 50 w:0 z:2 y:2 x:0 array(w,z,y,x): 50
i: 51 w:0 z:2 y:2 x:1 array(w,z,y,x): 51
i: 52 w:0 z:2 y:2 x:2 array(w,z,y,x): 52
i: 53 w:0 z:2 y:2 x:3 array(w,z,y,x): 53
i: 54 w:0 z:2 y:2 x:4 array(w,z,y,x): 54
i: 55 w:0 z:2 y:3 x:0 array(w,z,y,x): 55
i: 56 w:0 z:2 y:3 x:1 array(w,z,y,x): 56
i: 57 w:0 z:2 y:3 x:2 array(w,z,y,x): 57
i: 58 w:0 z:2 y:3 x:3 array(w,z,y,x): 58
i: 59 w:0 z:2 y:3 x:4 array(w,z,y,x): 59
i: 60 w:1 z:0 y:0 x:0 array(w,z,y,x): 60
i: 61 w:1 z:0 y:0 x:1 array(w,z,y,x): 61
i: 62 w:1 z:0 y:0 x:2 array(w,z,y,x): 62
i: 63 w:1 z:0 y:0 x:3 array(w,z,y,x): 63
i: 64 w:1 z:0 y:0 x:4 array(w,z,y,x): 64
i: 65 w:1 z:0 y:1 x:0 array(w,z,y,x): 65
i: 66 w:1 z:0 y:1 x:1 array(w,z,y,x): 66
i: 67 w:1 z:0 y:1 x:2 array(w,z,y,x): 67
i: 68 w:1 z:0 y:1 x:3 array(w,z,y,x): 68
i: 69 w:1 z:0 y:1 x:4 array(w,z,y,x): 69
i: 70 w:1 z:0 y:2 x:0 array(w,z,y,x): 70
i: 71 w:1 z:0 y:2 x:1 array(w,z,y,x): 71
i: 72 w:1 z:0 y:2 x:2 array(w,z,y,x): 72
i: 73 w:1 z:0 y:2 x:3 array(w,z,y,x): 73
i: 74 w:1 z:0 y:2 x:4 array(w,z,y,x): 74
i: 75 w:1 z:0 y:3 x:0 array(w,z,y,x): 75
i: 76 w:1 z:0 y:3 x:1 array(w,z,y,x): 76
i: 77 w:1 z:0 y:3 x:2 array(w,z,y,x): 77
i: 78 w:1 z:0 y:3 x:3 array(w,z,y,x): 78
i: 79 w:1 z:0 y:3 x:4 array(w,z,y,x): 79
i: 80 w:1 z:1 y:0 x:0 array(w,z,y,x): 80
i: 81 w:1 z:1 y:0 x:1 array(w,z,y,x): 81
i: 82 w:1 z:1 y:0 x:2 array(w,z,y,x): 82
i: 83 w:1 z:1 y:0 x:3 array(w,z,y,x): 83
i: 84 w:1 z:1 y:0 x:4 array(w,z,y,x): 84
i: 85 w:1 z:1 y:1 x:0 array(w,z,y,x): 85
i: 86 w:1 z:1 y:1 x:1 array(w,z,y,x): 86
i: 87 w:1 z:1 y:1 x:2 array(w,z,y,x): 87
i: 88 w:1 z:1 y:1 x:3 array(w,z,y,x): 88
i: 89 w:1 z:1 y:1 x:4 array(w,z,y,x): 89
i: 90 w:1 z:1 y:2 x:0 array(w,z,y,x): 90
i: 91 w:1 z:1 y:2 x:1 array(w,z,y,x): 91
i: 92 w:1 z:1 y:2 x:2 array(w,z,y,x): 92
i: 93 w:1 z:1 y:2 x:3 array(w,z,y,x): 93
i: 94 w:1 z:1 y:2 x:4 array(w,z,y,x): 94
i: 95 w:1 z:1 y:3 x:0 array(w,z,y,x): 95
i: 96 w:1 z:1 y:3 x:1 array(w,z,y,x): 96
i: 97 w:1 z:1 y:3 x:2 array(w,z,y,x): 97
i: 98 w:1 z:1 y:3 x:3 array(w,z,y,x): 98
i: 99 w:1 z:1 y:3 x:4 array(w,z,y,x): 99
i:100 w:1 z:2 y:0 x:0 array(w,z,y,x):100
i:101 w:1 z:2 y:0 x:1 array(w,z,y,x):101
i:102 w:1 z:2 y:0 x:2 array(w,z,y,x):102
i:103 w:1 z:2 y:0 x:3 array(w,z,y,x):103
i:104 w:1 z:2 y:0 x:4 array(w,z,y,x):104
i:105 w:1 z:2 y:1 x:0 array(w,z,y,x):105
i:106 w:1 z:2 y:1 x:1 array(w,z,y,x):106
i:107 w:1 z:2 y:1 x:2 array(w,z,y,x):107
i:108 w:1 z:2 y:1 x:3 array(w,z,y,x):108
i:109 w:1 z:2 y:1 x:4 array(w,z,y,x):109
i:110 w:1 z:2 y:2 x:0 array(w,z,y,x):110
i:111 w:1 z:2 y:2 x:1 array(w,z,y,x):111
i:112 w:1 z:2 y:2 x:2 array(w,z,y,x):112
i:113 w:1 z:2 y:2 x:3 array(w,z,y,x):113
i:114 w:1 z:2 y:2 x:4 array(w,z,y,x):114
i:115 w:1 z:2 y:3 x:0 array(w,z,y,x):115
i:116 w:1 z:2 y:3 x:1 array(w,z,y,x):116
i:117 w:1 z:2 y:3 x:2 array(w,z,y,x):117
i:118 w:1 z:2 y:3 x:3 array(w,z,y,x):118
i:119 w:1 z:2 y:3 x:4 array(w,z,y,x):119
[/code]
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » Jun 01, 2015 20:06

Hi, fxm, styling and all.

Well, I think that I have solved the problem with math.

The program does the following:
Knowing a position, we calculate the row, column, the level and dimension / block.

The data required are:
Know what position we want to search, and the number of rows, number of columns and the number of levels in a single dimension / block.

This program does the calculation for any dimension <= 4D.

Dimension> = 4D, indicates to block or dimension, the position belongs to look, then just make a couple of operations and obtain the correct position.

Code: Select all


DIM AS INTEGER C,CO,D,F,H,L,P,R

CLS

INPUT "QTY ROWS (Rows  <=  Cols)  = ";  R
INPUT "QTY COLS (Cols >=Rows)  = ";C
INPUT "QTY LEV   =  ";L
INPUT "FIND  POSITION  = ";P
H = L

'CALCULATE DIMENSION/BLOCK
IF  P MOD  (R*C*L)  <> 0 THEN
D =  INT(P/(R*C*L))+1
ELSE
D = INT(P/(R*C*L))
END IF
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

'CALCULATE  LEVEL
L =  INT(P/(R*C))+1
IF P  MOD (R*C)  =  0  THEN L  =  L-1
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

'CALCULATE COL
IF P  <  C THEN CO = P
IF P  >= C  THEN  CO =  P MOD  C
IF  P MOD C = 0 THEN  CO = C 
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

'CALCULATE ROW
F =  ((P-CO-((R*C)*(L-1)))/C)+1
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PRINT
COLOR  12
PRINT  "BLO = ";D;" ROW = ";F; " COL = ";CO; " LEV = ";L-((D-1)*H)
SLEEP
END



Simple example:
Calculate the row, column, and level of the position 26, in a 3D block 3 rows, 3 columns, 3 levels.
The solution is: row 3, column 2, Level 3

To calculate blocks / dimensions 4D, we simply indicate the size of a block and the position we want to search.

Simple example:
Calculate the row, column, and level of position 53, in a 3D block 3 rows, 3 columns, 3 levels.
The solution is: Dim / Blo 2 Row 3, column 2, Level 3.

To calculate blocks / size> = 4D, we simply indicate the size of a block and the position we want to search. The program will indicate that the block number is, the row, column and level.

I think some mathematical formulas, are faster and simple loops "For / Next".

I wish you like this program.!
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » Jun 02, 2015 6:16

To fxm:

Hi, fxm:

Your variables (I, J, K, L) are?

I = Row ? Col ?, Level? , Dim?
J = Row ? Col ?, Level? , Dim?
K = Row ?, Col ? , Level? , Dim?
L = Row ?, Col ?, Level? , Dim?

Regards
fxm
Posts: 8957
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Position item in an array larger than 3D

Postby fxm » Jun 02, 2015 8:25

Multidimensional arrays are stored in this definite order:
- values differing only in the last index are contiguous (row-major order).

So, referring to the notation:
array(I, J, K, L)
L is the row index
K is the column index
.....
.....

Example for a three-dimensional array:

Code: Select all

Dim As Integer array(1 To 3, 1 To 5, 1 To 4)

For J As Integer = Lbound(array, 1) To Ubound(array, 1)
  For K As Integer = Lbound(array, 2) To Ubound(array, 2)
    For L As Integer = Lbound(array, 3) To Ubound(array, 3)
      Print @array(J, K, L) - @array(Lbound(array, 1), Lbound(array, 2), Lbound(array, 3)),
    Next L
    Print
  Next K
  Print
Next J

Sleep

Code: Select all

 0             1             2             3
 4             5             6             7
 8             9             10            11
 12            13            14            15
 16            17            18            19

 20            21            22            23
 24            25            26            27
 28            29            30            31
 32            33            34            35
 36            37            38            39

 40            41            42            43
 44            45            46            47
 48            49            50            51
 52            53            54            55
 56            57            58            59
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » Jun 02, 2015 13:03

Hi, fxm

OK, is coincidence YOUR POST OF DATE 23.05.15
Block 3
Row 2
Col 2
Level 2

Thanks, regards!
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » Jun 02, 2015 18:14

Hi, fxm:

Your program is good, but the 1,1,1 position, can not be "0" has to be "1" and the last position is not 50, it must be = "60" = 4 * 5 * 3

Code: Select all

0 R =  1 C =  1 L =  1
1 R =  2 C =  1 L =  1
2 R =  3 C =  1 L =  1
3 R =  4 C =  1 L =  1

4 R =  1 C =  2 L =  1
5 R =  2 C =  2 L =  1
6 R =  3 C =  2 L =  1
7 R =  4 C =  2 L =  1

8 R =  1 C =  3 L =  1
9 R =  2 C =  3 L =  1
10 R =  3 C =  3 L =  1
11 R =  4 C =  3 L =  1

12 R =  1 C =  4 L =  1
13 R =  2 C =  4 L =  1
14 R =  3 C =  4 L =  1
15 R =  4 C =  4 L =  1

16 R =  1 C =  5 L =  1
17 R =  2 C =  5 L =  1
18 R =  3 C =  5 L =  1
19 R =  4 C =  5 L =  1


20 R =  1 C =  1 L =  2
21 R =  2 C =  1 L =  2
22 R =  3 C =  1 L =  2
23 R =  4 C =  1 L =  2

24 R =  1 C =  2 L =  2
25 R =  2 C =  2 L =  2
26 R =  3 C =  2 L =  2
27 R =  4 C =  2 L =  2

28 R =  1 C =  3 L =  2
29 R =  2 C =  3 L =  2
30 R =  3 C =  3 L =  2
31 R =  4 C =  3 L =  2

32 R =  1 C =  4 L =  2
33 R =  2 C =  4 L =  2
34 R =  3 C =  4 L =  2
35 R =  4 C =  4 L =  2

36 R =  1 C =  5 L =  2
37 R =  2 C =  5 L =  2
38 R =  3 C =  5 L =  2
39 R =  4 C =  5 L =  2


40 R =  1 C =  1 L =  3
41 R =  2 C =  1 L =  3
42 R =  3 C =  1 L =  3
43 R =  4 C =  1 L =  3

44 R =  1 C =  2 L =  3
45 R =  2 C =  2 L =  3
46 R =  3 C =  2 L =  3
47 R =  4 C =  2 L =  3

48 R =  1 C =  3 L =  3
49 R =  2 C =  3 L =  3
50 R =  3 C =  3 L =  3
51 R =  4 C =  3 L =  3

52 R =  1 C =  4 L =  3
53 R =  2 C =  4 L =  3
54 R =  3 C =  4 L =  3
55 R =  4 C =  4 L =  3

56 R =  1 C =  5 L =  3
57 R =  2 C =  5 L =  3
58 R =  3 C =  5 L =  3
59 R =  4 C =  5 L =  3





regards
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » Jun 02, 2015 18:16

HI, fxm:

My program:

Code: Select all

POS =  1 BLO =  1 ROW =  1 COL =  1 LEV =  1
POS =  2 BLO =  1 ROW =  1 COL =  2 LEV =  1
POS =  3 BLO =  1 ROW =  1 COL =  3 LEV =  1
POS =  4 BLO =  1 ROW =  1 COL =  4 LEV =  1
POS =  5 BLO =  1 ROW =  1 COL =  5 LEV =  1
POS =  6 BLO =  1 ROW =  2 COL =  1 LEV =  1
POS =  7 BLO =  1 ROW =  2 COL =  2 LEV =  1
POS =  8 BLO =  1 ROW =  2 COL =  3 LEV =  1
POS =  9 BLO =  1 ROW =  2 COL =  4 LEV =  1
POS =  10 BLO =  1 ROW =  2 COL =  5 LEV =  1
POS =  11 BLO =  1 ROW =  3 COL =  1 LEV =  1
POS =  12 BLO =  1 ROW =  3 COL =  2 LEV =  1
POS =  13 BLO =  1 ROW =  3 COL =  3 LEV =  1
POS =  14 BLO =  1 ROW =  3 COL =  4 LEV =  1
POS =  15 BLO =  1 ROW =  3 COL =  5 LEV =  1
POS =  16 BLO =  1 ROW =  4 COL =  1 LEV =  1
POS =  17 BLO =  1 ROW =  4 COL =  2 LEV =  1
POS =  18 BLO =  1 ROW =  4 COL =  3 LEV =  1
POS =  19 BLO =  1 ROW =  4 COL =  4 LEV =  1
POS =  20 BLO =  1 ROW =  4 COL =  5 LEV =  1
POS =  21 BLO =  2 ROW =  1 COL =  1 LEV =  1
POS =  22 BLO =  1 ROW =  1 COL =  2 LEV =  2
POS =  23 BLO =  1 ROW =  1 COL =  3 LEV =  2
POS =  24 BLO =  1 ROW =  1 COL =  4 LEV =  2
POS =  25 BLO =  1 ROW =  1 COL =  5 LEV =  2
POS =  26 BLO =  1 ROW =  2 COL =  1 LEV =  2
POS =  27 BLO =  1 ROW =  2 COL =  2 LEV =  2
POS =  28 BLO =  1 ROW =  2 COL =  3 LEV =  2
POS =  29 BLO =  1 ROW =  2 COL =  4 LEV =  2
POS =  30 BLO =  1 ROW =  2 COL =  5 LEV =  2
POS =  31 BLO =  1 ROW =  3 COL =  1 LEV =  2
POS =  32 BLO =  1 ROW =  3 COL =  2 LEV =  2
POS =  33 BLO =  1 ROW =  3 COL =  3 LEV =  2
POS =  34 BLO =  1 ROW =  3 COL =  4 LEV =  2
POS =  35 BLO =  1 ROW =  3 COL =  5 LEV =  2
POS =  36 BLO =  1 ROW =  4 COL =  1 LEV =  2
POS =  37 BLO =  1 ROW =  4 COL =  2 LEV =  2
POS =  38 BLO =  1 ROW =  4 COL =  3 LEV =  2
POS =  39 BLO =  1 ROW =  4 COL =  4 LEV =  2
POS =  40 BLO =  1 ROW =  4 COL =  5 LEV =  2
POS =  41 BLO =  2 ROW =  1 COL =  1 LEV =  1
POS =  42 BLO =  1 ROW =  1 COL =  2 LEV =  3
POS =  43 BLO =  1 ROW =  1 COL =  3 LEV =  3
POS =  44 BLO =  1 ROW =  1 COL =  4 LEV =  3
POS =  45 BLO =  1 ROW =  1 COL =  5 LEV =  3
POS =  46 BLO =  1 ROW =  2 COL =  1 LEV =  3
POS =  47 BLO =  1 ROW =  2 COL =  2 LEV =  3
POS =  48 BLO =  1 ROW =  2 COL =  3 LEV =  3
POS =  49 BLO =  1 ROW =  2 COL =  4 LEV =  3
POS =  50 BLO =  1 ROW =  2 COL =  5 LEV =  3
POS =  51 BLO =  1 ROW =  3 COL =  1 LEV =  3
POS =  52 BLO =  1 ROW =  3 COL =  2 LEV =  3
POS =  53 BLO =  1 ROW =  3 COL =  3 LEV =  3
POS =  54 BLO =  1 ROW =  3 COL =  4 LEV =  3
POS =  55 BLO =  1 ROW =  3 COL =  5 LEV =  3
POS =  56 BLO =  1 ROW =  4 COL =  1 LEV =  3
POS =  57 BLO =  1 ROW =  4 COL =  2 LEV =  3
POS =  58 BLO =  1 ROW =  4 COL =  3 LEV =  3
POS =  59 BLO =  1 ROW =  4 COL =  4 LEV =  3
POS =  60 BLO =  1 ROW =  4 COL =  5 LEV =  3




regards
fxm
Posts: 8957
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Position item in an array larger than 3D

Postby fxm » Jun 02, 2015 18:42

My program displays the offset of each element with regard to the first element (not the position):
Print @array(J, K, L) - @array(Lbound(array, 1), Lbound(array, 2), Lbound(array, 3))

So consequently:
- Offset of the 1 st element = 0
- Offset of the 60 th element = 59

(Offset = Position - 1)
lrcvs
Posts: 567
Joined: Mar 06, 2008 19:27
Location: Spain

Re: Position item in an array larger than 3D

Postby lrcvs » Jun 02, 2015 20:01

Hi, fxm:

Ok!, Both systems (programs) are correct!

Regards

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest