Seven is a hungry number and its favourite food is number 9. Whenever it spots 9
through the hoops of 8, it eats it! Well, not anymore, because you are 
going to help the 9 by locating that particular sequence (7,8,9) in an array of digits
and tell 7 to come after 9 instead. Seven "ate" nine, no more!
(If 9 is not in danger, just return the same array)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def hungry_seven(arr):
	

Solutions:
import re

def hungry_seven(arr):
	(ss, s) = ('', ''.join(map(str, arr)))
	while ss != s:
		(ss, s) = (s, re.sub('(7+)(89)', '\\2\\1', s))
	return list(map(int, s))


def hungry_seven(arr):
	s = str(arr)
	if '7, 8, 9' in s:
		return hungry_seven(s.replace('7, 8, 9', '8, 9, 7'))
	return eval(s)


import re
hungry_seven = lambda arr: (lambda h: lambda x: h(h, x))(lambda h, x: h(h, re.sub('(7+)(89)', '\\2\\1', x)) if re.search('(7+)(89)', x) else [int(c) for c in x])(''.join(map(str, arr)))


def hungry_seven(n):
	r = ''.join([str(x) for x in n])
	while '789' in r:
		for x in range(len(r)):
			if r[x:x + 3] == '789':
				r = r[:x] + r[x + 1:]
				r = r[:x + 2] + '7' + r[x + 2:]
	g = [int(x) for x in r]
	return g


import re

def hungry_seven(arr):
	s = ''.join(map(str, arr))
	while '789' in s:
		s = re.sub('7+89', lambda m: '89' + '7' * (len(m.group()) - 2), s)
	return list(map(int, s))


def hungry_seven(arr):
	nums = ''.join((str(a) for a in arr))
	while '789' in nums:
		nums = nums.replace('789', '897')
	return [int(n) for n in nums]


def hungry_seven(arr):
	s = ''.join(map(str, arr))
	if '789' in s:
		return hungry_seven(s.replace('789', '897'))
	return list(map(int, s))


def hungry_seven(arr):
	(i, a) = (0, arr[:])
	while i < len(a) - 2:
		if i >= 0 and a[i:i + 3] == [7, 8, 9]:
			a[i:i + 3] = [8, 9, 7]
			i -= 2
		i += 1
	return a


def hungry_seven(arr):
	for i in range(len(arr) - 2):
		if arr[i] == 7 and arr[i + 1] == 8 and (arr[i + 2] == 9):
			return hungry_seven(arr[:i] + arr[i + 1:i + 3] + [7] + arr[i + 3:])
	return arr


import re

def hungry_seven(arr):
	s = ''.join((str(v) for v in arr))
	while '789' in s:
		s = s.replace('789', '897')
	return [int(v) for v in s]