How many bees are in the beehive?

* bees can be facing UP, DOWN, LEFT, or RIGHT 
* bees can share parts of other bees

Examples

Ex1
```
bee.bee     
.e..e..
.b..eeb
```
*Answer: 5*


Ex2
```
bee.bee     
e.e.e.e
eeb.eeb
```
*Answer: 8*

# Notes

* The hive may be empty or null/None/nil/...
* Python: the hive is passed as a list of lists (not a list of strings)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def how_many_bees(hive):
	

Solutions:
from itertools import chain

def how_many_bees(hive):
	return bool(hive) and sum((s.count('bee') + s.count('eeb') for s in map(''.join, chain(hive, zip(*hive)))))


def count(it):
	return sum((''.join(x).count('bee') + ''.join(x).count('eeb') for x in it))

def how_many_bees(hive):
	return count(hive) + count(zip(*hive)) if hive else 0


def how_many_bees(hive):
	if hive == None or len(hive) == 0:
		return 0
	result = 0
	for i in range(len(hive[0])):
		test = ''
		for item in hive:
			test += item[i]
		result += test.count('bee')
		result += test.count('eeb')
	for i in range(len(hive)):
		test = ''
		for item in hive[i]:
			test += item
		result += test.count('bee')
		result += test.count('eeb')
	return result


import re

def how_many_bees(hive):
	if hive is None:
		return 0
	s = ' '.join((''.join(line) for hiveArr in (hive, zip(*hive)) for line in hiveArr))
	return len(re.findall('b(?=ee)|ee(?=b)', s))


def how_many_bees(hive):
	if not hive:
		return 0
	row_bees = lambda row: sum((1 for i in range(len(row)) if ''.join(row[i:i + 3]) == 'bee'))
	matrix_bees = lambda matrix: sum((row_bees(row) for row in matrix))
	v_flip = lambda matrix: [row[::-1] for row in matrix]
	transpose = lambda matrix: [list(z) for z in zip(*matrix)]
	return matrix_bees(hive) + matrix_bees(transpose(hive)) + matrix_bees(v_flip(hive)) + matrix_bees(v_flip(transpose(hive)))


def how_many_bees(hive):
	if hive is None:
		return 0
	columns = [''.join(col) for col in zip(*hive)]
	hive = [''.join(line) for line in hive]
	return sum((row.count(bee) for bee in ('bee', 'eeb') for rows in (hive, columns) for row in rows))


def how_many_bees(hive):
	counter = 0
	try:
		for row in hive:
			for i in range(len(row) - 2):
				if row[i] == 'b' and row[i + 1] == 'e' and (row[i + 2] == 'e'):
					counter += 1
				elif row[i] == 'e' and row[i + 1] == 'e' and (row[i + 2] == 'b'):
					counter += 1
		for column in range(len(hive[0])):
			for position in range(len(hive) - 2):
				if hive[position][column] == 'b' and hive[position + 1][column] == 'e' and (hive[position + 2][column] == 'e'):
					counter += 1
				if hive[position][column] == 'e' and hive[position + 1][column] == 'e' and (hive[position + 2][column] == 'b'):
					counter += 1
	except:
		counter = 0
	return counter


import re

def how_many_bees(b):
	if b is None:
		return 0
	new_temp = [[j for j in i] for i in b]
	c = [len(re.findall('bee', ''.join(i + [' '] + i[::-1]))) for i in new_temp] + [len(re.findall('bee', ''.join(i + tuple(' ') + i[::-1]))) for i in zip(*new_temp)]
	return sum(c)


directions = [(1, 0), (-1, 0), (0, -1), (0, 1)]

def how_many_bees(hive):
	(r, c) = (len(hive), len(hive[0])) if hive else (0, 0)

	def f(s, i, j, di, dj):
		if not (0 <= i < r and 0 <= j < c and s.startswith(hive[i][j])):
			return 0
		s = s[1:]
		return f(s, i + di, j + dj, di, dj) if s else 1
	return sum((f('bee', i, j, di, dj) for i in range(r) for j in range(c) for (di, dj) in directions))


VARIANTS = ['bee', 'eeb']

def how_many_bees(hive):
	count = 0
	if hive is None:
		return count
	rl = len(hive)
	for i in range(rl):
		cl = len(hive[i])
		for j in range(0, len(hive[i])):
			print('i=', i, 'j=', j)
			o = hive[i][j]
			if j < cl - 2:
				x1 = hive[i][j + 1]
				x2 = hive[i][j + 2]
				x = o + x1 + x2
				if x in VARIANTS:
					count += 1
			if i < rl - 2:
				y1 = hive[i + 1][j]
				y2 = hive[i + 2][j]
				y = o + y1 + y2
				if y in VARIANTS:
					count += 1
	return count


def how_many_bees(hive):
	if hive == [] or hive == '' or hive == None:
		return 0
	result = 0
	for i in range(len(hive)):
		for k in range(len(hive[i])):
			if i > 1 and hive[i][k] == 'b':
				if hive[i - 1][k] == 'e' and hive[i - 2][k] == 'e':
					result += 1
			if i < len(hive) - 2 and hive[i][k] == 'b':
				if hive[i + 1][k] == 'e' and hive[i + 2][k] == 'e':
					result += 1
			if k < len(hive[i]) - 2 and hive[i][k] == 'b':
				if hive[i][k + 1] == 'e' and hive[i][k + 2] == 'e':
					result += 1
			if k > 1 and hive[i][k] == 'b':
				if hive[i][k - 1] == 'e' and hive[i][k - 2] == 'e':
					result += 1
	return result


how_many_bees = lambda h: h and sum(map('|'.join(map(''.join, h + list(zip(*h)))).count, ('bee', 'eeb'))) or 0


import re
how_many_bees = lambda b: 0 if not b else sum([len(re.findall('bee', ''.join(i + [' '] + i[::-1]))) for i in b] + [len(re.findall('bee', ''.join(i + tuple(' ') + i[::-1]))) for i in zip(*b)])


def how_many_bees(hive):
	bees = ('bee', 'eeb')
	num_of_bees = 0
	if hive == None:
		return 0
	for line in hive:
		for pos in range(len(line) - 2):
			possible_bee = line[pos] + line[pos + 1] + line[pos + 2]
			if possible_bee in bees:
				num_of_bees += 1
	for line_idx in range(len(hive) - 2):
		for pos_idx in range(len(hive[line_idx])):
			possible_bee = hive[line_idx][pos_idx] + hive[line_idx + 1][pos_idx] + hive[line_idx + 2][pos_idx]
			if possible_bee in bees:
				num_of_bees += 1
	return num_of_bees


def how_many_bees(hive):
	if hive is None or len(hive) == 0:
		return 0
	cnt = 0
	for row in hive:
		cnt += ''.join(row).count('bee')
		cnt += ''.join(row).count('eeb')
	(m, n) = (len(hive), len(hive[0]))
	cols = [''.join([hive[j][i] for j in range(m)]) for i in range(n)]
	cnt += sum([i.count('bee') for i in cols])
	cnt += sum([i.count('eeb') for i in cols])
	return cnt


def rotate(matrix):
	return list(zip(*matrix[::-1]))

def how_many_bees(hive):
	if hive:
		s1 = ' '.join([''.join(r) for r in hive])
		s2 = ' '.join([''.join(el) for el in rotate(hive)])
		s = s1 + ' ' + s2
		return s.count('bee') + s.count('eeb')
	return 0


def how_many_bees(hive):
	if not hive:
		return 0
	count = 0
	for i in range(len(hive)):
		for j in range(len(hive[i]) - 2):
			compare = ''.join(hive[i][j:j + 3])
			if compare == 'bee' or compare == 'eeb':
				count += 1
	for i in range(len(hive) - 2):
		for j in range(len(hive[i])):
			compare = hive[i][j] + hive[i + 1][j] + hive[i + 2][j]
			if compare == 'bee' or compare == 'eeb':
				count += 1
	return count


how_many_bees = lambda h: (lambda m, tm: sum((sum((q.count(a) for q in b)) for a in ['bee', 'eeb'] for b in [m, tm])))([''.join(x) for x in h] if h else [], [''.join([h[p][q] for p in range(len(h))]) for q in range(0 if len(h) == 0 else len(h[0]))] if h else [])


def how_many_bees(hive):
	try:
		right = sum((line.count('bee') for line in map(''.join, hive)))
		left = sum((line.count('eeb') for line in map(''.join, hive)))
		down = sum((line.count('bee') for line in map(''.join, zip(*hive))))
		up = sum((line.count('eeb') for line in map(''.join, zip(*hive))))
		return up + down + left + right
	except TypeError:
		return 0


def how_many_bees(hive):
	return sum((word.count('eeb') + word.count('bee') for word in list(map(lambda x: ''.join(list(x)), zip(*hive))) + list(map(lambda x: ''.join(x), hive)))) if hive else 0