These days I'm solving Project Euler problems in Erlang.
Since I'm a C++ programmer from the beginning, sometimes I really want to code using two dimensional arrays.
One of my idea is to use tuples and lists like this:
List=[{X,0}||X<-lists:seq(1,3)]
{1,0}
{2,0}
{3,0}
Is there nice way to implement multidimensional arrays in Erlang?
In this program, the user is asked to enter the number of rows r and columns c . Then, the user is asked to enter the elements of the two matrices (of order rxc ). We then added corresponding elements of two matrices and saved it in another matrix (two-dimensional array). Finally, the result is printed on the screen.
More than Three Dimensions Although an array can have as many as 32 dimensions, it is rare to have more than three.
A multi-dimensional array is an array with more than one level or dimension. For example, a 2D array, or two-dimensional array, is an array of arrays, meaning it is a matrix of rows and columns (think of a table). A 3D array adds another dimension, turning it into an array of arrays of arrays.
In C programming, you can create an array of arrays. These arrays are known as multidimensional arrays.
See array module but for multidimensional access you have to write your own wrapper. If any of your dimension is short and access is mostly read you can use tuples and use erlang:element
and erlang:setelement
. Own wrapper is recommended anyway.
Try array(actually dict) with {X, Y, Z} as a key. It's look like 3d array ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With