You have to build a pyramid.

This pyramid should be built from characters from a given string.

You have to create the code for these four methods:
```python
watch_pyramid_from_the_side(characters):

watch_pyramid_from_above(characters):

count_visible_characters_of_the_pyramid(characters):

count_all_characters_of_the_pyramid(characters):
```

The first method ("FromTheSide") shows the pyramid as you would see from the side.
The second method ("FromAbove") shows the pyramid as you would see from above.
The third method ("CountVisibleCharacters") should return the count of all characters, that are visible from outside the pyramid.
The forth method ("CountAllCharacters") should count all characters of the pyramid. Consider that the pyramid is completely solid and has no holes or rooms in it.

Every character will be used for building one layer of the pyramid. So the length of the given string will be the height of the pyramid. Every layer will be built with stones from the given character. There is no limit of stones.
The pyramid should have perfect angles of 45 degrees.

Example: Given string: "abc"

Pyramid from the side:
```
  c
 bbb
aaaaa
```
Pyramid from above:
```
aaaaa
abbba
abcba
abbba
aaaaa
```
Count of visible stones/characters: 
```
25
```
Count of all used stones/characters:
```
35
```

There is no meaning in the order or the choice of the characters. It should work the same for example "aaaaa" or "54321".

Hint: Your output for the side must always be a rectangle! So spaces at the end of a line must not be deleted or trimmed!

If the string is null or empty, you should exactly return this value for the watch-methods and -1 for the count-methods.

Have fun coding it and please don't forget to vote and rank this kata! :-) 

I have created other katas. Have a look if you like coding and challenges.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Mathematics

Starter code: def watch_pyramid_from_the_side(characters):
	

Solutions:
def watch_pyramid_from_the_side(characters):
	if not characters:
		return characters
	baseLen = len(characters) * 2 - 1
	return '\n'.join((' ' * i + characters[i] * (baseLen - 2 * i) + ' ' * i for i in range(len(characters) - 1, -1, -1)))

def watch_pyramid_from_above(characters):
	if not characters:
		return characters
	baseLen = len(characters) * 2 - 1
	return '\n'.join((characters[0:min(i, baseLen - 1 - i)] + characters[min(i, baseLen - 1 - i)] * (baseLen - 2 * min(i, baseLen - 1 - i)) + characters[0:min(i, baseLen - 1 - i)][::-1] for i in range(baseLen)))

def count_visible_characters_of_the_pyramid(characters):
	return -1 if not characters else (len(characters) * 2 - 1) ** 2

def count_all_characters_of_the_pyramid(characters):
	return -1 if not characters else sum(((2 * i + 1) ** 2 for i in range(len(characters))))


def watch_pyramid_from_the_side(characters):
	if not characters:
		return characters
	width = 2 * len(characters) - 1
	output = '{{:^{}}}'.format(width).format
	return '\n'.join((output(char * dex) for (char, dex) in zip(reversed(characters), xrange(1, width + 1, 2))))

def watch_pyramid_from_above(characters):
	if not characters:
		return characters
	width = 2 * len(characters) - 1
	dex = width - 1
	result = []
	for a in xrange(width):
		row = []
		for b in xrange(width):
			(minimum, maximum) = sorted((a, b))
			row.append(characters[min(abs(dex - maximum), abs(0 - minimum))])
		result.append(''.join(row))
	return '\n'.join(result)

def count_visible_characters_of_the_pyramid(characters):
	if not characters:
		return -1
	return (2 * len(characters) - 1) ** 2

def count_all_characters_of_the_pyramid(characters):
	if not characters:
		return -1
	return sum((a ** 2 for a in xrange(1, 2 * len(characters), 2)))


def watch_pyramid_from_the_side(c, i=1, acc=[]):
	if c == None:
		return c
	if not c:
		return '\n'.join(acc)
	return watch_pyramid_from_the_side(c[:-1], i + 2, [' ' + l + ' ' for l in acc] + [c[-1] * i])

def watch_pyramid_from_above(c, i=1, acc=[]):
	if c == None:
		return c
	if not c:
		return '\n'.join(acc)
	return watch_pyramid_from_above(c[:-1], i + 2, [c[-1] * i] + [c[-1] + l + c[-1] for l in acc] + [c[-1] * i] * bool(acc))

def count_visible_characters_of_the_pyramid(c):
	return c and (2 * len(c) - 1) ** 2 or -1

def count_all_characters_of_the_pyramid(c):
	return c and (4 * len(c) ** 3 - len(c)) // 3 or -1


def watch_pyramid_from_the_side(characters):
	if not characters:
		return characters
	l = len(characters)
	return '\n'.join((' ' * (l - i - 1) + c * (2 * i + 1) + ' ' * (l - i - 1) for (i, c) in enumerate(characters[::-1])))

def watch_pyramid_from_above(characters):
	if not characters:
		return characters
	l = len(characters) * 2 - 1
	return '\n'.join((''.join((characters[min(i, j, l - i - 1, l - j - 1)] for j in range(l))) for i in range(l)))

def count_visible_characters_of_the_pyramid(characters):
	if not characters:
		return -1
	return 1 + sum((4 * i for i in range(2, 2 * len(characters), 2)))

def count_all_characters_of_the_pyramid(characters):
	if not characters:
		return -1
	return sum((i ** 2 for i in range(1, 2 * len(characters), 2)))


watch_pyramid_from_the_side = lambda c: '\n'.join([(j * (i * 2 + 1)).center(len(c) * 2 - 1) for (i, j) in enumerate(c[::-1])]) if c else c
count_visible_characters_of_the_pyramid = lambda c: (len(c) * 2 - 1) ** 2 if c else -1
count_all_characters_of_the_pyramid = lambda c: sum((k ** 2 for k in range(1, len(c) * 2, 2))) if c else -1

def watch_pyramid_from_above(c):
	above = [''.join(j).replace(' ', (c + c[:-1][::-1])[i]) for (i, j) in enumerate(zip(*watch_pyramid_from_the_side(c).splitlines()))] if c else []
	return '\n'.join([''.join(i) for i in list(zip(*above))[::-1][:-1] + list(zip(*above))]) if c else c


def watch_pyramid_from_the_side(characters):
	if not characters:
		return characters
	s = characters[::-1]
	n = len(s) * 2 - 1
	return '\n'.join(('{:^{}}'.format(c * i, n) for (i, c) in zip(range(1, len(s) * 2, 2), s)))

def watch_pyramid_from_above(characters):
	if not characters:
		return characters
	s = characters[::-1]
	n = len(s)
	return '\n'.join((''.join((s[max(abs(i), abs(j))] for j in range(-n + 1, n))) for i in range(-n + 1, n)))

def count_visible_characters_of_the_pyramid(characters):
	if not characters:
		return -1
	n = len(characters) * 2 - 1
	return n ** 2

def count_all_characters_of_the_pyramid(characters):
	if not characters:
		return -1
	return sum((n ** 2 for n in range(1, 2 * len(characters), 2)))


def watch_pyramid_from_the_side(characters=None):
	if characters is None:
		return None
	elif characters == '':
		return ''
	characters = characters[::-1]
	length = len(characters)
	output = []
	num = 1
	for i in range(len(characters)):
		output.append((length - i - 1) * ' ' + num * characters[i] + (length - i - 1) * ' ')
		num += 2
	return '\n'.join(output)

def watch_pyramid_from_above(characters=None):
	if characters is None:
		return None
	elif characters == '':
		return ''
	size = len(characters)
	output = []
	for i in range(size):
		output.append(characters[:i] + characters[i] * (size - 1 - i) + characters[i])
	output.extend(output[:-1][::-1])
	return '\n'.join([row + row[:-1][::-1] for row in output])

def count_visible_characters_of_the_pyramid(characters=None):
	if not characters:
		return -1
	return (len(characters) * 2 - 1) ** 2

def count_all_characters_of_the_pyramid(characters=None):
	if not characters:
		return -1
	return sum([(2 * num + 1) ** 2 for num in range(len(characters))])


import numpy as np

def watch_pyramid_from_the_side(characters):
	return characters and '\n'.join(((i + i * level * 2).center(len(characters) * 2 - 1) for (level, i) in enumerate(characters[::-1]))) or characters

def watch_pyramid_from_above(characters):
	to_char = lambda x: chr(x)
	int_to_char = np.vectorize(to_char)
	try:
		arr = np.asarray([ord(characters[-1])])[np.newaxis]
		for i in characters[::-1][1:]:
			arr = np.pad(arr, pad_width=1, mode='constant', constant_values=ord(i))
		return '\n'.join(map(''.join, int_to_char(arr).tolist()))
	except (TypeError, IndexError):
		return characters

def count_visible_characters_of_the_pyramid(characters):
	return characters and (len(characters) * 2 - 1) ** 2 or -1

def count_all_characters_of_the_pyramid(characters):
	return characters and sum(((1 + level * 2) ** 2 for (level, _) in enumerate(characters))) or -1


def watch_pyramid_from_the_side(characters):
	if not characters:
		return characters
	res = []
	length = len(characters)
	for i in range(length):
		res.append(' ' * (length - i - 1) + characters[-i - 1] * (i * 2 + 1) + ' ' * (length - i - 1))
	return '\n'.join(res)

def watch_pyramid_from_above(characters):
	if not characters:
		return characters
	length = len(characters) * 2 - 1
	res = [[None] * length for i in range(length)]
	for (i, char) in enumerate(characters):
		for j in range(i, length - i):
			res[i][j] = res[length - 1 - i][j] = res[j][i] = res[j][length - 1 - i] = char
	return '\n'.join((''.join(i) for i in res))

def count_visible_characters_of_the_pyramid(characters):
	return (len(characters) * 2 - 1) ** 2 if characters else -1

def count_all_characters_of_the_pyramid(characters):
	return sum((i ** 2 for i in range(1, len(characters) * 2, 2))) if characters else -1


def watch_pyramid_from_the_side(s):
	return '\n'.join((f"{' ' * (len(s) - i)}{(i * 2 - 1) * c}{' ' * (len(s) - i)}" for (i, c) in enumerate(reversed(s), 1))) if s else s

def watch_pyramid_from_above(s):
	if not s:
		return s
	n = len(s) - 1
	a = []
	for i in range(n + 1):
		a.append(s)
		n -= 1
		s = s[:n] + s[n] * (i + 2)
	a = [s + s[::-1][1:] for s in a]
	a = a[1:][::-1] + a
	return '\n'.join(a)

def count_visible_characters_of_the_pyramid(s):
	return (len(s) * 2 - 1) ** 2 if s else -1

def count_all_characters_of_the_pyramid(s):
	return sum((((n + 1) * 2 - 1) ** 2 for n in range(len(s)))) if s else -1