Crystal: How do I manipulate multidimensional vectors (matrix) in Crystal?

Created on 6 Jun 2017  路  2Comments  路  Source: crystal-lang/crystal

Hi, I need to scan a matrix in Crystal, but I found nothing in the documentation where it could be implemented in an "easy" way, as well as declaring the vectors.
How can I create a matrix of defined sizes and fill value in it as in the following code in C:

int matrix[DIM][DIM];
int rom, collumn;

for(row = 0 ; row < DIM ; row++)
    for(collumn = 0 ; collumn < DIM ; collumn++)
    {
        matrix[row][collumn] = 0;
    }

Most helpful comment

DIM = 5
matrix = Array.new(DIM) { |i| Array.new(DIM) { |j| 0 } }
p matrix

All 2 comments

DIM = 5
matrix = Array.new(DIM) { |i| Array.new(DIM) { |j| 0 } }
p matrix

Thanks, bro.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stugol picture stugol  路  70Comments

akzhan picture akzhan  路  67Comments

malte-v picture malte-v  路  77Comments

benoist picture benoist  路  59Comments

asterite picture asterite  路  71Comments