How to make 2d/3d int arrays in turing
Author |
Message |
ynotpeace
|
Posted: Tue Jan 05, 2010 6:20 pm Post subject: 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?
<Answer Here>
Describe what you have tried to solve this problem
<Answer Here>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
latest one |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
registration
|
Posted: Tue Jan 05, 2010 6:23 pm Post subject: 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? |
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Tue Jan 05, 2010 8:14 pm Post subject: RE:How to make 2d/3d int arrays in turing |
|
|
Basically Mutidemsional arrays just add the extra , low3 .. high3.
Turing: |
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
|
|
|
|
|
|
![](images/spacer.gif) |
DtY
![](http://compsci.ca/v3/uploads/user_avatars/8576159234be48b7a8b0e8.png)
|
Posted: Tue Jan 05, 2010 8:51 pm Post subject: 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:
Turing: | 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. |
|
|
|
|
![](images/spacer.gif) |
ynotpeace
|
Posted: Tue Jan 05, 2010 8:59 pm Post subject: Re: How to make 2d/3d int arrays in turing |
|
|
Thanks for all your help. |
|
|
|
|
![](images/spacer.gif) |
|
|