Arrays Transformation. Part 2. WRO Elementary 2013 Pro Preview

  • #226
  • 28 Aug 2016
  • 7:02

Courses with this episode

The episode is used in the following courses where you can find additional tasks for it to use in class

World Robotics Olympiad (WRO) 2013 Elementary. Review of solutions with explanations

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

Subscribe now to access the full capacity and get feedback.


- In this video, we will look at the details on how we transform this array of InRobots. So, these are the order of the blocks in the robot, and these are the sectors. And at the end, we want to arrive with an array where we say where we put each of the elements.

The program is not very easy, but once you get to know how to work with arrays, it's pretty understandable. And now we have the's array of five elements, and each element in each array has an index. And most of the programming languages in this world follow the following convention, the first element of the array has an index of zero. The second element has an index of one, and the third element has an index of two, three, four. So these are the values, two, two, one, one, three, and these are the indexes of elements, zero, one, two, three, four. So, the fifth element has an index of four. And that's a convention, and it applies to almost any programming language. Almost. There are exceptions of course. Now, for the second array where we have the sectors, we have zero, one, and two. And these are, again, the indexes of the elements. What we do now, is the following program: we take the value of two, right here, and with this value, we compare it. Is it equal to three? No. Is it equal to one? No. Is it equal to two? Yes. Then we take the index, multiply it by one, and we set this value right here as the first element of the places, which actually means the following: the element that is first on the robot should go to the third sector.

The same operation for the second element. Two is equal to three? No. Equal to one? No. To two? Yes, equal to two. Then, we increment the index with one, and we add it here. So three. So again, the second element, which is green, should go to the green sector, which is the third sector. And in this way, one should go to the second sector, and three should go to the first sector. And that's the idea of the program that we are now looking at. Once you get the idea, the whole program is pretty simple. Let's take a look at the program. The program works in the following way: first, we have a variable that's called current block index, and that's on which block we are currently when we are calculating the new place for the block. So there's the current block in this end, initially it is zero, and index is the...where we are currently in the sectors, in the array sectors, and places is the new array. So on the first loop of this whole loop, on the first iteration of the loop, current index will actually be equal to zero. And then, index will be equal to zero, and we do the following thing: we take the InRobot array, we take the InRobot array, and we take the first element from this array, which is with index zero. Then we take the first element of the sector's array, which is with index zero, and then we compare this. Is the value of the first element of the InRobot array equal to the value of the first element in the sector's array, and if they're equal, remember we have this situation here, when we have the first element...let me just use another two...from the first array, and the second, we compare their values. Are the values equal? And if they're not equal, then we just move to the second element, and then we just move to the third element. But if they're equal, which is the interesting part, then we take the index where we have found this element, and we add this index, we increment it with one, this here is a mathematical block to increment with one, and we set this to be the index of the value of the places array. And we write this value into the places array. And at the end, the places array, we will have the new value. We have a new value in it's first element within the zero, and this first value will be actually where we want to place the first element of the robot blocks. It gets complicated, I know. And this is because we have three arrays involved in this program. But again, if we have this visually, we do the following thing: so we have here the arrays, and we have here another array, another...and we compare this value with this value. And if both values are equal, then here we will add the value of one. So we must place this in the first block, in the first sector, on the field. And that's the idea for this program. As we have the final program, we have the Move To line, we have Find Places, which is only calculation, and then when we have the places where we must place each of the blocks, then we have Sort Blocks. And let's now see the whole program in action, especially here when we are placing. And to make it easier to understand arrays, we've prepared a number of tasks, so check them out below the video in the tasks sections. Try to computation to solve the problems, and give us a solution, share the solution with us. In the next video, we'll continue with other programs from the World Robotics Olympiad 2013 Challenge.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons