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!

Source: codewars | Difficulty: EASY
Tags: Data structures

Mathematics

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)]
	for i in range(1, n + 1):
		index = n * i - 1
		for j in range(1, i + 1):
			sqrList[index] = j
			index -= 1
	return sqrList


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):
	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


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