
-----------------------------------
ynotpeace
Tue Jan 05, 2010 6:20 pm

How to make 2d/3d int arrays in turing
-----------------------------------
What is it you are trying to achieve?

I am trying to make a 2d/ 3d int array but dont know how. can anyone help me?

What is the problem you are having?



Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)








Please specify what version of Turing you are using
latest one

-----------------------------------
registration
Tue Jan 05, 2010 6:23 pm

Re: How to make 2d/3d int arrays in turing
-----------------------------------
2D arrays:
var variableName : array low .. high, low2 .. high2 of type := init ()

not sure about 3D arrays.. why would you even need such a thing in turing?

-----------------------------------
Zren
Tue Jan 05, 2010 8:14 pm

RE:How to make 2d/3d int arrays in turing
-----------------------------------
Basically Mutidemsional arrays just add the extra , low3 .. high3.


const size := 3
var cube : array 1 .. size, 1 .. size, 1 .. size of int

for z : 1 .. size
    for y : 1 .. size
        for x : 1 .. size
            cube (x, y, z) := Rand.Int (0, 9)
        end for
    end for
end for

for z : 1 .. size
    for y : 1 .. size
        for x : 1 .. size
            put cube (x, y, z), "" ..
        end for
        put ""
    end for
    put ""
end for


-----------------------------------
DtY
Tue Jan 05, 2010 8:51 pm

RE:How to make 2d/3d int arrays in turing
-----------------------------------
You can also use the more literal syntax, this is the same example as Zren gave:

const size := 3
var cube: array 1..size of array 1..size of array 1..size of int

They both mean the same thing, except this version is more literal, the other is often easier to read.

When accessing them, you can index them with `cube(x,y,z)`, or `cube(x)(y)(z)`.
The second one actually makes more sense, imo.

-----------------------------------
ynotpeace
Tue Jan 05, 2010 8:59 pm

Re: How to make 2d/3d int arrays in turing
-----------------------------------
Thanks for all your help.
