This is a question from codingbat

Given an integer n greater than or equal to 0,
create and return an array with the following pattern:

    squareUp(3) => [0, 0, 1, 0, 2, 1, 3, 2, 1]
    squareUp(2) => [0, 1, 2, 1]
    squareUp(4) => [0, 0, 0, 1, 0, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 1]
n<=1000.

# Check out my other kata!

        
Matrix Diagonal Sort OMG
String -> N iterations -> String
String -> X iterations -> String
ANTISTRING
Array - squareUp b!
Matrix - squareUp b!
Infinitely Nested Radical Expressions
pipi Numbers!

Difficulty: introductory

Starter code:

def square_up(n):
	

Solutions:
def square_up(n):
    return [j if j <= i else 0 for i in range(1, n+1) for j in range(n, 0, -1)]


def square_up(n):
    result = []
    for i in range(1, n + 1):
        result.extend([0] * (n - i) + list(range(i, 0,  -1)))
    return result
    



def square_up(n):
    lst = []
    max = 1
    while max <=n:
        for x in range(n,0,-1):
            if x-max < 1:
                lst.append(x)
            else:
                lst.append(0)
        max+=1

    return lst

from itertools import chain, repeat

def square_up(n):
    return list(chain.from_iterable(
        chain(repeat(0, n-i), range(i, 0, -1))
        for i in range(1, n+1)
    ))

def square_up(n):
    x = list(range(n,0,-1))
    y = [ ([0] * i + x[i:]) for i in range(n-1,-1,-1)    ]
    return [i for l in y for  i in l] 


def square_up(n):
    sqrList = [0 for _ in range(n*n)]

    #we build the square list, from right to left, in sets
    # e.g. for n==5  [5i-1,  5i-2,  5i-3,  5i-4, 5i-5]  for i = 1,2,...,n
    for i in range(1,n+1):          #iterate over the  1,2,...,n sets
        index = n*i - 1             #Start the index in the right most index of the set n
        for j in range(1, i+1):     #pattern: 1, 1;2, 1;2;3, 1;2;3;4, ..., 1;2;3;;;n 
            sqrList[index] = j
            index -=1

    return sqrList
#-----end function


def square_up(n):
    a = []
    for j in range(1,n+1):
        for i in range(n, j, -1):
            a.append(0)
        for i in range(j, 0, -1):
            a.append(i)
    return a


def square_up(n):
    """
    Codewars 练习题: Array - squareUp b!
    :param n:
    :return:
    """
    ans = []
    for i in range(1, n + 1):
        for k in range(n - i):
            ans.append(0)
        for j in range(i, 0, -1):
            ans.append(j)
    return ans

def square_up(n):
    return [n - j if n - j - 1 <= i else 0 for i in range(n) for j in range(n)]

square_up=lambda n:sum([[0]*(i-1)+list(range(n,0,-1))[i-1:] for i in range(n,0,-1)], [])