Grid/__init__.py
def flat_to_diagonal(n : int, i : int) -> Tuple[int,int]:
    '''
    flat_to_diagonal
    ================
    Sequences the squares in diagonal coordinates on a square matrix. 
    
    Parameters
    ----------
    n : int
        The row and column size.
        Diagonal coordinates are only defined for square matrices.
    i : int
        the index in the flat array

    Returns
    -------
    Tuple[int, int]
        The resulting diagonal coordinate.
    '''
    if i < n*(n+1)//2:
        # complex equation derived mathematically
        a = floor( sqrt( 2*i + 0.25 ) - 0.5 )
        b = i - (1+a)*a//2
        return a,b
    else:
        # more complex equation derived mathematically
        a = floor( n + 0.5 - sqrt( 2 * ( n * n - i) + 0.25 ) ) - 1
        b = i - n*(n+1)//2 - (2*n-1-a)*a//2 - 1
        return (n + a, b+1)

    flat_to_diagonal
    ================
    Sequences the squares in diagonal coordinates on a square matrix. 
    
    Parameters
    ----------
    n : int
        The row and column size.
        Diagonal coordinates are only defined for square matrices.
    i : int
        the index in the flat array

    Returns
    -------
    Tuple[int, int]
        The resulting diagonal coordinate.
    
flat_to_diagonal
Sequences the squares in diagonal coordinates on a square matrix.

Parameters

n : int
The row and column size.
Diagonal coordinates are only defined for square matrices.
i : int
the index in the flat array

Returns

Tuple[int, int]
The resulting diagonal coordinate.
flat_to_diagonal Sequences the squares in diagonal coordinates on a square matrix . Parameters n : int The row and column size . Diagonal coordinates are only defined for square matrices . i : int the index in the flat array Returns Tuple [ int int ] The resulting diagonal coordinate .
def flat_to_diagonal(n : int, i : int) -> Tuple[int,int]:
    if i < n*(n+1)//2:
        a = floor( sqrt( 2*i + 0.25 ) - 0.5 )
        b = i - (1+a)*a//2
        return a,b
    else:
        a = floor( n + 0.5 - sqrt( 2 * ( n * n - i) + 0.25 ) ) - 1
        b = i - n*(n+1)//2 - (2*n-1-a)*a//2 - 1
        return (n + a, b+1)
def flat_to_diagonal ( n : int , i : int ) -> Tuple [ int , int ] : if i < n * ( n + 1 ) // 2 : a = floor ( sqrt ( 2 * i + 0.25 ) - 0.5 ) b = i - ( 1 + a ) * a // 2 return a , b else : a = floor ( n + 0.5 - sqrt ( 2 * ( n * n - i ) + 0.25 ) ) - 1 b = i - n * ( n + 1 ) // 2 - ( 2 * n - 1 - a ) * a // 2 - 1 return ( n + a , b + 1 )
flat_to_diagonal
Sequences the squares in diagonal coordinates on a square matrix.
flat_to_diagonal Sequences the squares in diagonal coordinates on a square matrix .
'''
    flat_to_diagonal
    ================
    Sequences the squares in diagonal coordinates on a square matrix. 
    
    Parameters
    ----------
    n : int
        The row and column size.
        Diagonal coordinates are only defined for square matrices.
    i : int
        the index in the flat array

    Returns
    -------
    Tuple[int, int]
        The resulting diagonal coordinate.
    ''' # complex equation derived mathematically # more complex equation derived mathematically
n
int
i
int