The Spelling Bee bees are back...

# How many bees are in the beehive?

* bees can be facing UP, DOWN, LEFT, RIGHT, and now also _diagonally_ up/down/left/right
* bees can share parts of other bees



## Examples

Ex1
```
bee.bee     
.e..e..
.b..eeb
```
_Answer: 5_

Ex2
```
beee..     
eeb.e.
ebee.b
```
_Answer: 7_

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def how_many_bees(hive):
	

Solutions:
def how_many_bees(h):
	if not h:
		return 0
	v = list(zip(*h))
	b = [None] * len(h)
	sf = (b[i:] + l + b[:i] for (i, l) in enumerate(h))
	sb = (b[:i] + l + b[i:] for (i, l) in enumerate(h))
	df = [[n for n in l if n is not None] for l in zip(*sf)]
	db = [[n for n in l if n is not None] for l in zip(*sb)]
	inline = '\n'.join(map(''.join, h + v + df + db))
	return (inline + inline[::-1]).count('bee')


def how_many_bees(hive):
	if not hive:
		return 0
	hive = [list(x) for x in hive]
	directions = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1)]
	output = 0
	for (row, _) in enumerate(hive):
		for (col, val) in enumerate(_):
			curr = 'b'
			if val == 'b':
				for direction in directions:
					coord = (row + direction[0], col + direction[1])
					if inBounds(hive, coord) and hive[coord[0]][coord[1]] == 'e':
						output += traverse(hive, coord, direction, curr)
	return output

def traverse(hive, coord, direction, curr):
	curr += hive[coord[0]][coord[1]]
	new_c = (coord[0] + direction[0], coord[1] + direction[1])
	if curr == 'bee':
		return 1
	if inBounds(hive, new_c):
		return traverse(hive, new_c, direction, curr)
	return 0

def inBounds(hive, coord):
	(row, col) = (len(hive), len(hive[0]))
	if 0 <= coord[0] < row and 0 <= coord[1] < col:
		return True
	return False


def find_bee_heads(hive):
	for (i, row) in enumerate(hive):
		for (j, x) in enumerate(row):
			if x == 'b':
				yield (i, j)

def count_ee(hive, r, c, i, j):
	return sum((0 <= i + di * 2 < r and 0 <= j + dj * 2 < c and (hive[i + di][j + dj] == hive[i + di * 2][j + dj * 2] == 'e') for (di, dj) in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]))

def how_many_bees(hive):
	hive = hive or []
	r = len(hive)
	c = r and len(hive[0])
	return sum((count_ee(hive, r, c, i, j) for (i, j) in find_bee_heads(hive)))


def how_many_bees(hive):
	if not hive or len(hive) < 3 or len(hive[0]) < 3:
		return 0
	rn90 = lambda a: [list(x) for x in zip(*a[::-1])]
	r45 = lambda a: [[val for (r, row) in enumerate(a) for (c, val) in enumerate(row) if r + c == i][::-1] for i in range(len(a) + len(a[0]))]
	bees = lambda a: sum((''.join(r).count('bee') for r in a))
	dbees = lambda a: bees(r45(a))
	result = bees(hive) + bees(rn90(hive)) + bees(rn90(rn90(hive))) + bees(rn90(rn90(rn90(hive))))
	result += dbees(hive) + dbees(rn90(hive)) + dbees(rn90(rn90(hive))) + dbees(rn90(rn90(rn90(hive))))
	return result


def how_many_bees(hive):
	if type(hive) != list:
		return 0
	n = 0
	l = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
	for x in range(len(hive)):
		for y in range(len(hive[x])):
			if hive[x][y] == 'b':
				for i in l:
					if 0 <= x + i[0] * 2 < len(hive) and 0 <= y + i[1] * 2 < len(hive[x]) and (hive[x + i[0]][y + i[1]] == 'e') and (hive[x + i[0] * 2][y + i[1] * 2] == 'e'):
						n += 1
	return n


def how_many_bees(hive):
	if not hive:
		return 0
	r = 0
	for row in hive:
		r += ''.join(row).count('bee')
		r += ''.join(row[::-1]).count('bee')
	for column in zip(*hive):
		r += ''.join(column).count('bee')
		r += ''.join(column[::-1]).count('bee')
	(m, n) = (len(hive), len(hive[0]))
	for i in range(m):
		for j in range(n):
			if hive[i][j] == 'b':
				if i < m - 2 and j < n - 2:
					if hive[i + 1][j + 1] == hive[i + 2][j + 2] == 'e':
						r += 1
				if i < m - 2 and j >= 2:
					if hive[i + 1][j - 1] == hive[i + 2][j - 2] == 'e':
						r += 1
				if i >= 2 and j < n - 2:
					if hive[i - 1][j + 1] == hive[i - 2][j + 2] == 'e':
						r += 1
				if i >= 2 and j >= 2:
					if hive[i - 1][j - 1] == hive[i - 2][j - 2] == 'e':
						r += 1
	return r


def how_many_bees(hive):
	if not hive:
		return 0

	def gather_bees(row, col):
		h = col < len(hive[row]) - 2
		if h:
			yield (hive[row][col] + hive[row][col + 1] + hive[row][col + 2])
		v = row < len(hive) - 2
		if v:
			yield (hive[row][col] + hive[row + 1][col] + hive[row + 2][col])
		if h and v:
			yield (hive[row][col] + hive[row + 1][col + 1] + hive[row + 2][col + 2])
			yield (hive[row + 2][col] + hive[row + 1][col + 1] + hive[row][col + 2])
	count = 0
	for row in range(len(hive)):
		for col in range(len(hive[row])):
			count += sum((1 for x in gather_bees(row, col) if x in ['bee', 'eeb']))
	return count


def how_many_bees(hive):
	if not hive:
		return 0
	new_hive = [[i for i in line] for line in hive]
	result = 0
	for line in range(len(hive)):
		for i in range(len(hive[0])):
			if hive[line][i] == 'b':
				if len(hive[0]) - i > 2 and hive[line][i + 1] == 'e' and (hive[line][i + 2] == 'e'):
					result += 1
				if i > 1 and hive[line][i - 1] == 'e' and (hive[line][i - 2] == 'e'):
					result += 1
				if len(hive) - line > 2 and hive[line + 1][i] == 'e' and (hive[line + 2][i] == 'e'):
					result += 1
				if line > 1 and hive[line - 1][i] == 'e' and (hive[line - 2][i] == 'e'):
					result += 1
				if len(hive[0]) - i > 2 and len(hive) - line > 2 and (hive[line + 1][i + 1] == 'e') and (hive[line + 2][i + 2] == 'e'):
					result += 1
				if i > 1 and line > 1 and (hive[line - 1][i - 1] == 'e') and (hive[line - 2][i - 2] == 'e'):
					result += 1
				if len(hive[0]) - i > 2 and line > 1 and (hive[line - 1][i + 1] == 'e') and (hive[line - 2][i + 2] == 'e'):
					result += 1
				if i > 1 and len(hive) - line > 2 and (hive[line + 1][i - 1] == 'e') and (hive[line + 2][i - 2] == 'e'):
					result += 1
	return result


def how_many_bees(hive):
	if not hive:
		return 0
	hive_matrix = [list(line) for line in hive]
	max_col = len(hive_matrix[0])
	max_row = len(hive_matrix)
	cols = [[] for _ in range(max_col)]
	rows = [[] for _ in range(max_row)]
	fdiag = [[] for _ in range(max_row + max_col - 1)]
	bdiag = [[] for _ in range(len(fdiag))]
	min_bdiag = -max_row + 1
	for x in range(max_col):
		for y in range(max_row):
			cols[x].append(hive_matrix[y][x])
			rows[y].append(hive_matrix[y][x])
			fdiag[x + y].append(hive_matrix[y][x])
			bdiag[x - y - min_bdiag].append(hive_matrix[y][x])
	h1 = '\n'.join([''.join(line) for line in cols])
	h11 = h1.count('bee') + h1.count('eeb')
	v1 = '\n'.join([''.join(line) for line in rows])
	v11 = v1.count('bee') + v1.count('eeb')
	d1 = '\n'.join((''.join(line) for line in fdiag))
	d11 = d1.count('bee') + d1.count('eeb')
	d2 = '\n'.join((''.join(line) for line in bdiag))
	d22 = d2.count('bee') + d2.count('eeb')
	return h11 + v11 + d11 + d22


def how_many_bees(hive):
	if not hive or not len(hive) or (not len(hive[0])):
		return 0

	class Model(object):

		def __init__(self):
			self.bees = 0

		def checker(self, row, col):
			if row > 1 and hive[row - 1][col] == 'e' and (hive[row - 2][col] == 'e'):
				self.bees += 1
			if row < len(hive) - 2 and hive[row + 1][col] == 'e' and (hive[row + 2][col] == 'e'):
				self.bees += 1
			if col > 1 and hive[row][col - 1] == 'e' and (hive[row][col - 2] == 'e'):
				self.bees += 1
			if col < len(hive[0]) - 2 and hive[row][col + 1] == 'e' and (hive[row][col + 2] == 'e'):
				self.bees += 1
			if row > 1 and col > 1 and (hive[row - 1][col - 1] == 'e') and (hive[row - 2][col - 2] == 'e'):
				self.bees += 1
			if row < len(hive) - 2 and col > 1 and (hive[row + 1][col - 1] == 'e') and (hive[row + 2][col - 2] == 'e'):
				self.bees += 1
			if row > 1 and col < len(hive[0]) - 2 and (hive[row - 1][col + 1] == 'e') and (hive[row - 2][col + 2] == 'e'):
				self.bees += 1
			if row < len(hive) - 2 and col < len(hive[0]) - 2 and (hive[row + 1][col + 1] == 'e') and (hive[row + 2][col + 2] == 'e'):
				self.bees += 1
	b = Model()
	for i in range(len(hive)):
		for j in range(len(hive[i])):
			if hive[i][j] == 'b':
				b.checker(i, j)
	return b.bees