How to calculate (x,y) position of number in square I am looking for a way to determine the X & Y position of a number to draw following square:
1   2   5   10  17
3   4   6   11
7   8   9   12
13  14  15  16

What kind of algorithm / formula can I use ?
I have tried rounding the square root of the number to determine the X position.
To be clear, here is what I want to achieve, numbers with their corresponding X and Y position:
#  X  Y
1: 1  1
2: 2  1
3: 1  2
4: 2  2
5: 3  1
6: 3  2


Here is an algorithm (written for Matlab) that works:
n = 5;

x = zeros(n*n,1);
y = zeros(n*n,1);

x(1) = 1;  % set the first 3 points
y(1) = 1;
x(2) = 2;
y(2) = 1;
x(3) = 1;
y(3) = 2;

for i = 4:n*n
    if (x(i-1) == y(i-1))       % jump all the way down (and 1 to the right)
        x(i) = x(i-1)+1;    
        y(i) = 1;
    elseif (x(i-1) == y(i-1)+1) % jump all the way to the left (and 1 up)
        x(i) = 1;           
        y(i) = y(i-1)+1;
    elseif (x(i-1) > y(i-1))    % move 1 up
        x(i) = x(i-1);
        y(i) = y(i-1)+1;
    else        
        x(i) = x(i-1)+1;        % move 1 to the right
        y(i) = y(i-1);
    end
end 

If at the end you call plot(x,y) you get the following figure:

