Jamie is a programmer, and James' girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn't know how to make this happen, he needs your help.

## Task

You need to return a string that looks like a diamond shape when printed on the screen, using asterisk (`*`) characters. Trailing spaces should be removed, and every line must be terminated with a newline character (`\n`).

Return `null/nil/None/...` if the input is an even number or negative, as it is not possible to print a diamond of even or negative size.


## Examples

A size 3 diamond:

```
 *
***
 *
```

...which would appear as a string of `" *\n***\n *\n"`


A size 5 diamond:

```
  *
 ***
*****
 ***
  *
```

...that is: `"  *\n ***\n*****\n ***\n  *\n"`

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def diamond(n):
	

Solutions:
def diamond(n):
	if n < 0 or n % 2 == 0:
		return None
	result = '*' * n + '\n'
	spaces = 1
	n = n - 2
	while n > 0:
		current = ' ' * spaces + '*' * n + '\n'
		spaces = spaces + 1
		n = n - 2
		result = current + result + current
	return result


def diamond(n):
	w = ''
	space = n // 2
	starnum = 1
	while starnum < n:
		w += space * ' ' + starnum * '*' + '\n'
		starnum += 2
		space -= 1
	while starnum > 0:
		w += space * ' ' + starnum * '*' + '\n'
		starnum -= 2
		space += 1
	return w if n % 2 != 0 and n > 0 else None


def diamond(n):
	if n % 2 == 0 or n <= 0:
		return None
	diamond = ''
	for i in range(n):
		length = getLength(i, n)
		diamond += getLine(length, n)
	return diamond

def getLine(len, max):
	spaces = (max - len) // 2
	return ' ' * spaces + '*' * len + '\n'

def getLength(index, max):
	distance = abs(max // 2 - index)
	return max - distance * 2


def diamond(n):
	return ''.join([('*' * k).center(n).rstrip() + '\n' for k in range(1, n + 1, 2)] + [('*' * k).center(n).rstrip() + '\n' for k in range(n - 2, 0, -2)]) if n > 0 and n % 2 == 1 else None