jeudi 21 septembre 2017

Program the following number pattern

I want to device an algorithm to display the following pattern:

1  
9 2  
10 8 3  
14 11 7 4  
15 13 12 6 5  

Is there a way to convert it into the following array and use the indices of the above matrix and find out the position of the number in the array: 1 9 2 10 8 3 ...

I can't find a pattern to calculate the element using the matrix co-ordinates, that is why I was trying to device the above method of somehow determining the position of the next number in the array.

Aucun commentaire:

Enregistrer un commentaire