Consider an array containing cats and dogs. Each dog can catch only one cat, but cannot catch a cat that is more than `n` elements away. Your task will be to return the maximum number of cats that can be caught.

For example:
```Haskell
solve(['D','C','C','D','C'], 2) = 2, because the dog at index 0 (D0) catches C1 and D3 catches C4. 
solve(['C','C','D','D','C','D'], 2) = 3, because D2 catches C0, D3 catches C1 and D5 catches C4.
solve(['C','C','D','D','C','D'], 1) = 2, because D2 catches C1, D3 catches C4. C0 cannot be caught because n == 1.
solve(['D','C','D','D','C'], 1) = 2, too many dogs, so all cats get caught!
```

Do not modify the input array. 

More examples in the test cases. Good luck!

Source: codewars | Difficulty: EASY

Starter code: def solve(arr,n):
	

Solutions:
def solve(arr, reach):
	(dogs, nCats) = ({i for (i, x) in enumerate(arr) if x == 'D'}, 0)
	for (i, c) in enumerate(arr):
		if c == 'C':
			catchingDog = next((i + id for id in range(-reach, reach + 1) if i + id in dogs), None)
			if catchingDog is not None:
				nCats += 1
				dogs.remove(catchingDog)
	return nCats


def solve(lst, n):
	(lst, caught) = (lst[:], 0)
	while {'C', 'D'} <= set(lst):
		(d, c) = (lst.index('D'), lst.index('C'))
		if abs(d - c) <= n:
			(caught, lst[d], lst[c]) = (caught + 1, '', '')
		else:
			lst[min(d, c)] = ''
	return caught


def solve(arr, n):
	dogs = [i for (i, x) in enumerate(arr) if x == 'D']
	cats = {i for (i, x) in enumerate(arr) if x == 'C'}
	catch = 0
	while dogs and cats:
		dog = dogs.pop()
		cat = max((cat for cat in cats if abs(dog - cat) <= n), default=-1)
		if cat >= 0:
			catch += 1
			cats.remove(cat)
	return catch


def solve(arr, n):
	(c, l) = (0, len(arr))
	for i in range(l):
		if arr[i] == 'C':
			a = max(0, i - n)
			b = min(l - 1, i + n)
			for j in range(a, b + 1):
				if arr[j] == 'D':
					arr[j] = 'd'
					c += 1
					break
	return c


def solve(arr, n):
	caught = 0
	for i in range(0, len(arr)):
		if arr[i] == 'C':
			for j in range(0, len(arr)):
				if abs(i - j) <= n and arr[j] == 'D' and (arr[i] != 'X'):
					(arr[i], arr[j]) = ('X', 'X')
					caught += 1
	return caught


def solve(d, pos):
	for (i, j) in enumerate(d):
		if j == 'D':
			left = next((k for k in range(i - pos if i - pos > -1 else 0, i) if d[k] == 'C'), -1)
			right = next((k for k in range(i, i + pos + 1 if i + pos < len(d) else len(d)) if d[k] == 'C'), -1)
			if left != -1:
				d[left] = '.'
			elif right != -1:
				d[right] = '.'
	return d.count('.')


def solve(arr, n):
	caught = []
	for d in [idx for idx in range(len(arr)) if arr[idx] == 'D']:
		for c in [idx for idx in range(len(arr)) if arr[idx] == 'C']:
			if c in range(d - n, d + n + 1) and c not in caught:
				caught += [c]
				break
	return len(caught)


def solve(arr, n):
	dc = n * ['x'] + arr[:] + n * ['x']
	p = 0
	ct = 0
	while p < len(dc):
		if dc[p] == 'D':
			for i in range(p - n, p + n + 1):
				if dc[i] == 'C':
					dc[i] = 'X'
					ct += 1
					break
		p += 1
	return ct


def solve(arr, n):
	eaten = []
	dog = []
	for i in range(len(arr)):
		if arr[i] == 'D':
			for j in range(max(0, i - n), min(1 + i + n, len(arr))):
				if arr[j] == 'C' and j not in eaten and (i not in dog):
					dog.append(i)
					eaten.append(j)
	return len(eaten)


def solve(arr, n):
	a = [''] * n + arr[:] + [''] * n
	r = 0
	for (i, e) in enumerate(a):
		if e == 'D':
			for j in range(i - n, i + n + 1):
				if a[j] == 'C':
					r += 1
					a[j] = ''
					break
	return r