def spiral_path(twoDList):
    # r = rows
    # c = columns
    r = len(twoDList)
    ## If the Two-Dimensional Array Is Empty, return an empty array.
    if r == 0:
        return []
    ## Length of the First Row
    c = len(twoDList[0])

    result = []
    ## x = starting row index
    ## r = ending row index

    ## y = starting column index
    ## c = ending column index
    x = 0
    y = 0
    
    while x < r and y < c:
        ## Add the first row to the array (right to left) based on 
        ## the ending column index
        
        for i in range(y,c):
            result.append(twoDList[x][i])
        x += 1

        # Add the last column from the remaining columns 
        # from the remaining columns
        
        for i in range(x,r):
            result.append(twoDList[i][c-1])
        c -= 1
        
        # Add the last row from the remaining rows
        
        if x < r:
            for i in range(c-1,y-1,-1):
                result.append(twoDList[r-1][i])
            r -= 1

        # Add the first column from the remaining columns

        if y < c :
            for i in range(r-1,x-1,-1):
                result.append(twoDList[i][y])
            y += 1

    return result

## Helper Function

def isPrime(num):
    if num > 1:
        for i in range(2, num):
            if (num % i == 0):
                return False
            else:
                return True

## Harshad number = a number which is divisible by the sum of its digits ex. 32 / 6## (1 + 3 + 2). 

## Moran Number(subset of the Harshad numbers) = a prime number when divide by thesum of their digits ex. 133 / 6 (1 + 3 + 2) = 19 

def moran_test(num):
    remainder = 0
    sumOfDigits = 0
    ## Set temporary value as num is going to change
    ## in the while loop
    n = num

    #Finds the sum of the digits
    while(num):
        remainder = num % 10
        sumOfDigits += remainder
        num //= 10
    # Store possible prime value to check 
    
    possiblePrime = n // sumOfDigits

    if(isPrime(possiblePrime)):
        return "M"
    elif (n % sumOfDigits == 0):
        return "H"
    else:
        return "Neither"

def shortest_words(string):

    shortestWordLength = 999
    wordsList = string.split()
    shortestWordList = []

    #First find the shortest word length in the string
    for word in wordsList:
        if len(word) <= shortestWordLength:
            shortestWordLength = len(word)

    # Then add words to new array if they are not in the 
    # new list and the same length.
    # Changes to lowercase because it takes uppercase as unique value
    for word in wordsList:
        if len(word) == shortestWordLength:
            if word.lower() not in shortestWordList:
                shortestWordList.append(word.lower())

    # Returns sorted alphabetically
    return sorted(shortestWordList)
    

def num_to_words(num):
    ## Python Dictionary to hold keys of values to the value strings
    numList = { 0 : 'zero', 1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', 6 : 'six', 7 : 'seven', 8 : 'eight', 9 : 'nine', 10 : 'ten', 11 : 'eleven', 12 : 'twelve', 13 : 'thirteen', 14 : 'fourteen', 15 : 'fifteen', 16 : 'sixteen', 17 : 'seventeen', 18 : 'eighteen', 19 : 'nineteen', 20 : 'twenty', 30 : 'thirty', 40 : 'forty', 50 : 'fifty', 60 : 'sixty', 70 : 'seventy', 80 : 'eighty', 90 : 'ninty' }
    ## Can only go up to 999
    k = 1000
    ## If it can be returned into one word, just return the value
    if (num < 20):
	return numList[num]
    ## If it carries a zero value, return as one word. 
    ## Or else it will return the tenth value concactenated onto the number
    if (num < 100):
        if num % 10 == 0:
            return numList[num]
        else:
            ## return numList [num // 100]
            ## Returns 0 
            return numList[num // 10 * 10] + ' ' + numList[num % 10]
    ## Similar but based on tenths to hundreds and calls function within
    if (num < k):
        if num % 100 == 0:
            return numList[num // 100] + ' hundred'
        else:
            return numList[num // 100] + ' hundred ' + num_to_words(num % 100)

def main():
    ans = spiral_path([[1, 2], [5, 0]])
    ans1 = spiral_path([[1, 2, 3], [8,9,4], [7,6,5]])
    ans2 = spiral_path([[1,1,1], [4,5,2],[3,3,2]])
            
    print(ans)
    print(ans1)
    print(ans2)

    ans3 = moran_test(132)
    ans4 = moran_test(133)
    ans5 = moran_test(134)
    print(ans3)
    print(ans4)
    print(ans5)
    
    ans6 = shortest_words("I think the solution is fairly obvious.")
    ans7 = shortest_words("Chase two rabbits, catch none.")
    ans8 = shortest_words("We become what we think about.")
    ans9 = shortest_words('The quick brown fox jumps over the lazy dogs.')
    print(ans6)
    print(ans7)
    print(ans8)
    print(ans9)

    ans10 = num_to_words(0)
    ans11 = num_to_words(18)
    ans12 = num_to_words(126)
    ans13 = num_to_words(909)
    print(ans10)
    print(ans11)
    print(ans12)
    print(ans13)

main()
