Display a matrix with "life" and "dead" cells on the EV3 LEGO Mindstorms brick screen. The program is available. You can see it, change it, modify it and learn from it.

**#256**- 17 Mar 2016
- 5:27

At the end we have three alive cells and the rest are dead.

In the program there are different variables for columns, rows and size.

But there is also one more available variable and this is "MyArr".

MyArr is an array. The array contains a number of different elements. If the value of an element is 1, then the cell is alive. If the value is 0, then the cell is dead.

The first four values of the array represent the first row of the matrix. Not the column, but the row.

Tasks for modifying the program and displaying different matrix on the brick screen.

#### Tasks description, submission and evaluation are available to subscribed users.

Subscribe now to access the full capacity and get feedback.

### English

With the previous program we already learned how to display a grid, a matrix on the screen and to have different number of rows and columns and our next step is to learn how to display the different cells as alive or dead. So that we can have different states of the cells. And that's the subject of today's video.

What we'll have in the end is to run the program and display a new grid, a new matrix 4x4 with 3 of the cells makred as alive. Let's see how we can do this in the program. Again, it's available for downloading below the video and we'll experiment and change some of the values in this program. This here is the whole program and it's pretty familiar. It looks like the previous programs. It again has a variable called size, a variable called rows and a variable called columns. Again it's mistyped but let's think for now that this is columns. And we can set the number of columns, the number of rows and we can also set the size of the different squares. What we can also do is look at this additional variable here that's called MyArray. And in this MyArray we can set the different cells which are alive and which are dead. You can see that we have a dead cell that means it has a value of 0. Then an alive, then dead, dead and by 1 we specify alive and by 0 we specify a dead cell. Let's modify some of the values. For example, this one to be with a value 1, and this one to be with a value 1, and because our matrix is with a size 4x4 the first 4 values here are the values of the first row. The second 4 values are the values of the second row. And the third are the values of the third row and we have the fourth row. For example, this would be the bottom right cell. If we said this cell to be alive. And now download and run the program.

As you can see we have the grid and we have the bottom right cell that's alive because we've marked it with 1 in the array. To experiment with using arrays we'll set another configuration. Let's try to change the value of the rows and columns to 1. So, you'll have 2 columns and 2 rows. This is the case when we have 2 columns - 0 and 1 and 2 rows - 0 and 1. And we'd like to fill these two cells. The diagonal. And for this we would have to fill our array. And our array is just a sequence of zeros and ones. And it's first the first row then the second row then the third row. And looking at the values of the different cells for the first cell we should have 0. For the second cell we should have 1. For the third cell, this one here because we have fitst, second, third, fourth cell. For the third cell we also have 1 and for the final cell we have 0. So, this should be the configuration of our array in order to display this seed on the brick screen. Now, let's go to the program and program it to display it on the brick screen.

First, I will set the rows to be 2 and the columns to be 2. And the first 4 digits of the array must be 0, then 1, then 1, then 0. And these are the first 4 digits of our array. Run the program.

As you can see we have the grid. It has 2 rows and 2 columns and we have the top right and the bottom left cells as alive. What you have to do now is change this to 3x3, 4x4, 5x5. So, there are a number of tasks below. Try to solve them and to modify the size of our grid. And again, of course, set the diagonal to be alive. All the cells on the diagonal to be alive.

## Lessons with this tutorial

This tutorial is used in the following lessons