"""
Generate transitive closure of a matrix
"""

def TC(matrix, size):
    """
    given n by n matrix of bits R, modify its contents
    to be the transive closure of what was given.
    """
    for i in range(size):
        for j in range(size):
            if matrix[j][i]:
                matrix[j] = map(lambda a,b: a or b, 
                                matrix[i],
                                matrix[j])
        
def RTC(matrix, size):
    """
    Reflexive Transitive Closure.  Same as TC
    and then set all the bits on the diagonal of R.
    """
    TC(matrix, size)
    
    for i in range(size):
        matrix[i][i] = 1
            
    return
