#!/bin/python
import math

def doolittle(mat):
    size = len(mat) #Size of the input matrix
    L = [ [0]*size for i in range(size)] #Create lower triangular
    U = [ [0]*size for i in range(size)] #Create upper triangular
    for i in range(size): #Create assumption that L is unitriangular under doolittle algorithm
        L[i][i] = 1
    for col in range(size): 
        for row in range(size):
            if row <= col: #Solve for  U index
                U[row][col] = mat[row][col]
                for i in range(row): 
                    U[row][col] = U[row][col] - L[row][i]*U[i][col]
            else: #Solve for L index
                L[row][col] = mat[row][col] 
                for i in range(col):
                    L[row][col] = L[row][col] - L[row][i]*U[i][col]
                L[row][col] = L[row][col] / U[col][col]
    return [L,U]





print(doolittle([[1,1,1,1],[8,4,2,1],[27,9,3,1],[64,16,4,1]]))
