# Right in the Center

_This is inspired by one of Nick Parlante's exercises on the [CodingBat](https://codingbat.com/java) online code practice tool._

Given a sequence of characters, does `"abc"` appear in the CENTER of the sequence?

The sequence of characters could contain more than one `"abc"`.

To define CENTER, the number of characters in the sequence to the left and right of the "abc" (which is in the middle) must differ by at most one.

If it is in the CENTER, return `True`. Otherwise, return `False`.

Write a function as the solution for this problem. This kata looks simple, but it might not be easy.

## Example

    is_in_middle("AAabcBB")  ->  True
    is_in_middle("AabcBB")   ->  True
    is_in_middle("AabcBBB")  ->  False

Difficulty: EASY
Starter code: def is_in_middle(s):
	

Solutions:
def is_in_middle(s):
	while len(s) > 4:
		s = s[1:-1]
	return 'abc' in s


def is_in_middle(seq):
	(mid, rem) = divmod(len(seq), 2)
	start = mid - 1
	end = start + 3
	if not rem:
		start -= 1
	return 'abc' in seq[start:end]


def is_in_middle(s):
	return is_in_middle(s[1:-1]) if s[4:] else 'abc' in s


def is_in_middle(sequence):
	n = len(sequence)
	i = (n - 3) // 2
	return sequence[i:i + 3] == 'abc' or (n % 2 == 0 and sequence[i + 1:i + 4] == 'abc')


def is_in_middle(sequence):
	while len(sequence) >= 3:
		if sequence == 'abc' or sequence[1:] == 'abc' or sequence[:-1] == 'abc':
			return True
		sequence = sequence[1:-1]
	return False


def is_in_middle(sequence):
	length = len(sequence)
	if length < 3:
		return False
	if length % 2 != 0:
		index = length // 2 - 1
		if sequence[index:index + 3] == 'abc':
			return True
		return False
	elif length % 2 == 0:
		index1 = length // 2 - 2
		index2 = length // 2 - 1
		if sequence[index1:index1 + 3] == 'abc' or sequence[index2:index2 + 3] == 'abc':
			return True
		return False


def in_centre(s, i):
	return s[i] == 'a' and s[i + 1] == 'b' and (s[i + 2] == 'c')

def is_in_middle(s):
	if 'abc' not in s or len(s) < 3:
		return False
	l = len(s)
	if l % 2 == 1:
		i = (l + 1) // 2 - 2
		return in_centre(s, i)
	else:
		i1 = l // 2 - 2
		i2 = l // 2 - 1
		return in_centre(s, i1) or in_centre(s, i2)


def is_in_middle(s):
	return 'abc' in s[(len(s) - 1) // 2 - 1:(len(s) + 2) // 2 + 1]


def is_in_middle(seq):
	m = len(seq) // 2
	if len(seq) % 2 != 0 and seq[m - 1:m + 2] == 'abc':
		return True
	elif len(seq) % 2 == 0:
		if seq[m - 2:m + 1] == 'abc' or seq[m - 1:m + 2] == 'abc':
			return True
	return False


def is_in_middle(s):
	return 'abc' in [s[len(s) // 2 - 1:len(s) // 2 + 2] if len(s) % 2 else s[len(s) // 2 - 2:len(s) // 2 + 2]][0]