Original Post
hello, im running with a little problem on an algorithm lets say i have this array of size N(N+1)/2, where N is the size of the 2D matrix that represents it, in this case N=5: A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]. i need to map it to a 2D triangular matrix: A[5][5] = 0..1..2...3...4 -..5..6...7...8 -..-..9...10..11 -..-..-...12..13 -..-..-....-..14 so, what im trying to do is an algorithm that receives as parameter a given index x= 0..14, and returns i,j of the matrix. for example. function(0) returns i=0, j=0. function(7) returns i=1, j=3. function(11) return i=2, j=4. function(14) returns i=4, j=4. i have came up with different algorithms, one worked for 3x3 Matrixes, but i cannot figure out the generic ecuation for any square triangle matrix. any help is welcome, meanwhile i will keep trying. EDIT: From my análisis, the key is to calculate "i", since j can be calculated very easy after that. [Edited by - Chire on March 20, 2010 6:05:51 PM]