# Question: How do we show an object "falling" inside a matrix?

import copy


# How do we print a matrix?
def printM(matrix):
    for row in matrix:
        for item in row:
            print(item + " ", end=' ')
        print()
    print("\n-----------------\n")

def printM2(matrix):
    for row in matrix:
        print(" ".join(row))



# What is the difference between these two kinds of falls?
def fall(matrix):
    done = False
    while not done:
        printM(matrix)
        done = True
        for rowNum in range(len(matrix)-1)[::-1]:
            for colNum in range(len(matrix[rowNum])):
                if matrix[rowNum][colNum]=="X" and matrix[rowNum+1][colNum]==".":
                    temp = matrix[rowNum][colNum]
                    matrix[rowNum][colNum]= matrix[rowNum+1][colNum]
                    matrix[rowNum+1][colNum]= temp
                    done = False


def fall2(matrix):
    newMatrix=copy.deepcopy(matrix)
    for rowNum in range(len(matrix)-1):
        for colNum in range(len(matrix[rowNum])):
            if matrix[rowNum][colNum]=="X" and matrix[rowNum+1][colNum]==".":
                newMatrix[rowNum][colNum]   =  matrix[rowNum+1][colNum]
                newMatrix[rowNum+1][colNum] =  matrix[rowNum][colNum]
    return newMatrix


a = [["." for i in range(10)] for j in range(10)]
a[2][3]="X"
a[3][3]="X"
a[4][4]="X"

fall(a)




        

