My little sister came back home from school with the following task:
given a squared sheet of paper she has to cut it in pieces
which, when assembled, give squares the sides of which form
an increasing sequence of numbers.
At the beginning it was lot of fun but little by little we were tired of seeing the pile of torn paper.
So we decided to write a program that could help us and protects trees.

## Task

Given a positive integral number n, return a **strictly increasing** sequence (list/array/string depending on the language) of numbers, so that the sum of the squares is equal to n².

If there are multiple solutions (and there will be), return as far as possible the result with the largest possible values:

## Examples

`decompose(11)` must return `[1,2,4,10]`. Note that there are actually two ways to decompose 11²,
11² = 121 = 1 + 4 + 16 + 100 = 1² + 2² + 4² + 10² but don't return `[2,6,9]`, since 9 is smaller than 10.

For `decompose(50)` don't return `[1, 1, 4, 9, 49]` but `[1, 3, 5, 8, 49]` since `[1, 1, 4, 9, 49]`
doesn't form a strictly increasing sequence.

## Note
Neither `[n]` nor `[1,1,1,…,1]` are valid solutions. If no valid solution exists, return `nil`, `null`, `Nothing`, `None` (depending on the language) or `"[]"` (C) ,`{}` (C++), `[]` (Swift, Go).

The function "decompose" will take a positive integer n 
and return the decomposition of N = n² as:

- [x1 ... xk]
or
- "x1 ... xk"
or
- Just [x1 ... xk]
or
- Some [x1 ... xk]
or
- {x1 ... xk}
or
- "[x1,x2, ... ,xk]"

depending on the language (see "Sample tests")

# Note for Bash
```
decompose 50 returns "1,3,5,8,49"
decompose 4  returns "Nothing"
```
# Hint

Very often `xk` will be `n-1`.

Source: codewars | Difficulty: MEDIUM_HARD
Tags: Mathematics

Starter code: def decompose(n):
	

Solutions:
def decompose(n):
	total = 0
	answer = [n]
	while len(answer):
		temp = answer.pop()
		total += temp ** 2
		for i in range(temp - 1, 0, -1):
			if total - i ** 2 >= 0:
				total -= i ** 2
				answer.append(i)
				if total == 0:
					return sorted(answer)
	return None


def decompose(n, a=None):
	if a == None:
		a = n * n
	if a == 0:
		return []
	for m in range(min(n - 1, int(a ** 0.5)), 0, -1):
		sub = decompose(m, a - m * m)
		if sub != None:
			return sub + [m]


import math

def decompose(n):
	if n <= 4:
		return None
	result = [n - 1]
	remain = n ** 2 - (n - 1) ** 2
	while True:
		if not remain:
			return list(reversed(result))
		if result[0] == 1:
			return None
		if result[-1] == 1:
			remain += result.pop() ** 2
			result[-1] -= 1
			remain += (result[-1] + 1) ** 2 - result[-1] ** 2
		else:
			i = min(result[-1] - 1, int(math.floor(math.sqrt(remain))))
			result.append(i)
			remain -= i ** 2


import math

def decompose(n):
	value = n - 1
	remains = n ** 2
	cache = {value: remains}
	remains -= value ** 2
	while remains:
		value = int(math.sqrt(remains))
		if value < min(cache.keys()):
			cache[value] = remains
			remains -= value ** 2
		else:
			del cache[min(cache.keys())]
			if not cache:
				return None
			value = min(cache.keys())
			remains = cache.pop(value)
			cache[value - 1] = remains
			remains -= (value - 1) ** 2
	return sorted(cache.keys())


import math

def decompose_aux(nb, rac):
	if nb == 0:
		return []
	i = rac
	l = None
	while i >= int(math.sqrt(nb / 2.0)) + 1:
		diff = nb - i * i
		rac = int(math.sqrt(diff))
		l = decompose_aux(diff, rac)
		if l != None:
			l.append(i)
			return l
		i -= 1
	return l

def decompose(n):
	l = decompose_aux(n * n, int(math.sqrt(n * n - 1)))
	if l != None:
		return l
	else:
		return None


def decompose(n):

	def fun(s, i):
		if s < 0:
			return None
		if s == 0:
			return []
		for j in range(i - 1, 0, -1):
			some = fun(s - j ** 2, j)
			if some != None:
				return some + [j]
	return fun(n ** 2, n)


def dec(r, d):
	for i in range(d - 1, 0, -1):
		if r < i * i:
			continue
		if r == i * i:
			return [i]
		a = dec(r - i * i, i)
		if a:
			return a + [i]
	return None

def decompose(n):
	return dec(n * n, n)


def decompose(n):
	return decompose_helper(n ** 2, n - 1)

def decompose_helper(n, end):
	for i in range(end, 0, -1):
		if i ** 2 == n:
			return [i]
		new = n - i ** 2
		d = decompose_helper(new, min(i - 1, int(new ** 0.5)))
		if d:
			return d + [i]