# Task

Christmas is coming, and your task is to build a custom Christmas tree with the specified characters and the specified height.

# Inputs:
- `chars`: the specified characters. 
- `n`: the specified height. A positive integer greater than 2.

# Output:
- A multiline string. Each line is separated by `\n`. A tree contains two parts: leaves and trunks. 

The leaves should be `n` rows. The first row fill in 1 char, the second row fill in 3 chars, and so on. A single space will be added between two adjust chars, and some of the necessary spaces will be added to the left side, to keep the shape of the tree. No space need to be added to the right side.

The trunk should be at least 1 unit height, it depends on the value of the `n`. The minimum value of n is 3, and the height of the tree trunk is 1 unit height. If `n` increased by 3, and the tree trunk increased by 1 unit. For example, when n is 3,4 or 5, trunk should be 1 row; when n is 6,7 or 8, trunk should be 2 row; and so on.

Still not understand the task? Look at the following example ;-)

# Examples

For `chars = "*@o" and n = 3`,the output should be:
```
  *
 @ o
* @ o
  |
```

For `chars = "*@o" and n = 6`,the output should be:
```
     *
    @ o
   * @ o
  * @ o *
 @ o * @ o
* @ o * @ o
     |
     |
```

For `chars = "1234" and n = 6`,the output should be:
```
     1
    2 3
   4 1 2
  3 4 1 2
 3 4 1 2 3
4 1 2 3 4 1
     |
     |
```

For `chars = "123456789" and n = 3`,the output should be:
```
  1
 2 3
4 5 6
  |
```

Difficulty: EASY
Tags: String algorithms

Ad-hoc

Starter code:
def custom_christmas_tree(chars, n):
	

Solutions:
def custom_christmas_tree(chars, n):
	from itertools import cycle
	it = cycle(chars)
	tree = [' '.join((next(it) for j in range(i))).center(2 * n).rstrip() for i in range(1, n + 1)]
	tree.extend(('|'.center(2 * n).rstrip() for _ in range(n // 3)))
	return '\n'.join(tree)


from itertools import cycle, chain

def custom_christmas_tree(chars, n):
	(c, l) = (cycle(chars), 2 * n - 1)
	return '\n'.join(chain((' '.join((next(c) for _ in range(i))).center(l).rstrip() for i in range(1, n + 1)), ('|'.center(l).rstrip() for _ in range(n // 3 or 1))))


class Chaos(object):
	pass

class Nature(Chaos):

	def buildTree(self, luck):
		n = luck
		tree = ''
		for i in range(1, n + 1):
			temp_layer = Leafs.get_leaf(self)
			for j in range(0, i - 1):
				temp_layer += ' '
				temp_layer += Leafs.get_leaf(self)
			tree += ' ' * (n - i) + temp_layer + '\n'
		for i in range(n // 3):
			if i == n // 3 - 1:
				tree += ' ' * (n - 1) + Trunk.pieceOfTrunk(self)
				break
			tree += ' ' * (n - 1) + Trunk.pieceOfTrunk(self) + '\n'
		return tree

class Leafs(Nature):

	def __init__(self, leaftypes):
		self.leaftypes = leaftypes
		self.nextleaf = 0

	def get_leaf(self):
		self.nextleaf += 1
		leaft = self.leaftypes
		return leaft[(self.nextleaf - 1) % len(leaft)]

class Trunk(Nature):

	def pieceOfTrunk(self):
		return '|'

def custom_christmas_tree(chars, n):
	yaprak = Leafs(chars)
	life = Nature.buildTree(yaprak, n)
	return life


from itertools import chain, cycle, islice, repeat

def custom_christmas_tree(chars, n):
	it = cycle(chars)
	leaves = (' '.join(islice(it, i)).center(2 * n - 1).rstrip() for i in range(1, n + 1))
	trunk = repeat('|'.rjust(n), n // 3)
	return '\n'.join(chain(leaves, trunk))


from itertools import cycle

def custom_christmas_tree(chars, height):
	ornament = cycle(chars)
	lines = []
	for n in range(1, height + 1):
		lines += [' ' * (height - n) + ' '.join((next(ornament) for _ in range(0, n)))]
	for n in range(height // 3):
		lines += [' ' * (height - 1) + '|']
	return '\n'.join(lines)


def custom_christmas_tree(chars, n):
	trunc = n // 3
	string = ''
	(l, i) = (len(chars), 0)
	for r in range(n):
		string += ' ' * (n - r - 1)
		for c in range(r + 1):
			string += chars[i % l]
			string += ' ' if c < r else '\n'
			i += 1
	for r in range(trunc):
		string += ' ' * (n - 1) + '|'
		string += '\n' if r < trunc - 1 else ''
	return string


def custom_christmas_tree(chars, n):
	chars *= n * n
	s = lambda n: (n + 1) * n // 2
	pad = lambda s: ' ' * (n - len(s) // 2 - 1) + s
	row = lambda i: pad(' '.join(chars[s(i):s(i) + i + 1]))
	return '\n'.join([*map(row, range(n))] + [pad('|')] * (n // 3))


from itertools import cycle

def custom_christmas_tree(chars, n):
	leaf_provider = cycle(chars)
	trunk_height = n // 3
	max_width = 2 * n - 1
	tree = []

	def build_row(provider, row_number):
		return ' '.join([provider.__next__() for _ in range(row_number)])

	def padding(row_number):
		return ' ' * (max_width // 2 - (2 * row_number - 1) // 2)

	def build_trunk():
		return [padding(1) + '|' for _ in range(trunk_height)]
	for i in range(n):
		tree.append(padding(i + 1) + build_row(leaf_provider, i + 1))
	tree.extend(build_trunk())
	return '\n'.join(tree)


from itertools import cycle

def custom_christmas_tree(chars, n):
	(l, s) = (cycle(chars), lambda i=0: ' ' * (n - 1 - i))
	return '\n'.join([s(i) + ' '.join((next(l) for _ in range(i + 1))) for i in range(n)] + [f'{s()}|' for _ in range(n // 3)])


from itertools import cycle

def custom_christmas_tree(chars, n):
	space = lambda i=0: ' ' * (n - 1 - i)
	leaf = cycle(chars)
	body = [space(i) + ' '.join((next(leaf) for _ in range(i + 1))) for i in range(n)]
	body.extend([f'{space()}|' for _ in range(n // 3)])
	return '\n'.join(body)