Number is a palindrome if it is equal to the number with digits in reversed order.
For example, 5, 44, 171, 4884 are palindromes and 43, 194, 4773 are not palindromes.

Write a method `palindrome_chain_length` which takes a positive number and returns the number of special steps needed to obtain a palindrome. The special step is: "reverse the digits, and add to the original number". If the resulting number is not a  palindrome, repeat the procedure with the sum until the resulting number is a palindrome.

If the input number is already a palindrome, the number of steps is 0.

Input will always be a positive integer.

For example, start with 87:

87 + 78 = 165;
165 + 561 = 726;
 726 + 627 = 1353;
1353 + 3531 = 4884

4884 is a palindrome and we needed 4 steps to obtain it, so `palindrome_chain_length(87) == 4`

Difficulty: EASY
Starter code: def palindrome_chain_length(n):
	

Solutions:
def palindrome_chain_length(n):
	steps = 0
	while str(n) != str(n)[::-1]:
		n = n + int(str(n)[::-1])
		steps += 1
	return steps


def palindrome_chain_length(n, count=0):
	if str(n) == str(n)[::-1]:
		return count
	else:
		return palindrome_chain_length(n + int(str(n)[::-1]), count + 1)


def is_palindrome(n):
	return str(n) == str(n)[::-1]

def palindrome_chain_length(n):
	steps = 0
	while not is_palindrome(n):
		steps += 1
		n += int(str(n)[::-1])
	return steps


def palindrome_chain_length(n, times=0):
	reversed = int(str(n)[::-1])
	if reversed == n:
		return times
	return palindrome_chain_length(n + reversed, times + 1)


def palindrome_chain_length(n):
	count = 0
	while str(n) != str(n)[::-1]:
		count += 1
		n += int(str(n)[::-1])
	return count


def palindrome_chain_length(n):
	steps = 0
	while True:
		reverse_n = int(str(n)[::-1])
		if n == reverse_n:
			return steps
			break
		else:
			n += reverse_n
			steps += 1


def palindrome_chain_length(n):
	return n != int(str(n)[::-1]) and palindrome_chain_length(n + int(str(n)[::-1])) + 1


from itertools import takewhile, accumulate, repeat

def palindrome_chain_length(n):
	return len(list(takewhile(lambda x: str(x) != str(x)[::-1], accumulate(repeat(n), lambda m, _: m + int(str(m)[::-1])))))


def palindrome_chain_length(n):
	counter = 0
	while str(n) != str(n)[::-1]:
		n += int(str(n)[::-1])
		counter += 1
	if counter > 0:
		return counter
	return 0


def palindrome_chain_length(num):
	steps = 0
	while True:
		tmp = str(num)
		rev = tmp[::-1]
		if tmp == rev:
			return steps
		num += int(rev)
		steps += 1


palindrome_chain_length = lambda n, i=0: i if str(n) == str(n)[::-1] else palindrome_chain_length(n + int(str(n)[::-1]), i + 1)


from functools import lru_cache

@lru_cache(maxsize=None)
def palindrome_chain_length(n):
	s1 = str(n)
	s2 = s1[::-1]
	return s1 != s2 and 1 + palindrome_chain_length(n + int(s2))


def palindrome_chain_length(n, step=0):
	return step if str(n) == str(n)[::-1] else palindrome_chain_length(n + int(str(n)[::-1]), step + 1)


def palindrome(n):
	s = str(n)
	return s == s[::-1]

def palindrome_chain_length(n):
	n_chain = 0
	while not palindrome(n):
		n += int(str(n)[::-1])
		n_chain += 1
	return n_chain


def palindrome_chain_length(n):
	i = 0
	while True:
		if n == int(str(n)[::-1]):
			return i
		n += int(str(n)[::-1])
		i += 1


def palindrome_chain_length(n):
	ct = 0
	while str(n) != str(n)[::-1]:
		n += int(str(n)[::-1])
		ct += 1
	return ct


def palindrome_chain_length(n):

	def calculate_palindrome(steps, n):
		if str(n)[::-1] == str(n):
			return steps
		else:
			return calculate_palindrome(steps + 1, n + int(str(n)[::-1]))
	return calculate_palindrome(0, n)


def palindrome_chain_length(n):
	(counter, last_num) = (0, n)

	def reverse_num(a_num):
		return str(a_num)[::-1]

	def is_palindrome(sum_num):
		return reverse_num(sum_num) == str(sum_num)
	while not is_palindrome(last_num):
		last_num = last_num + int(reverse_num(last_num))
		counter += 1
	return counter


def palindrome_chain_length(n):
	x = 0
	while n != int(str(n)[::-1]):
		n = n + int(str(n)[::-1])
		x += 1
	return x


from itertools import takewhile

def palindrome_chain_length(n):

	def next_palindrome(m):
		while 1:
			yield m
			m = m + int(str(m)[::-1])
	return len(list(takewhile(lambda x: str(x) != str(x)[::-1], next_palindrome(n))))


def palindrome_chain_length(n):
	digits_reversed = lambda n: int(str(n)[::-1])
	steps = 0
	last_n = n
	last_n_rev = digits_reversed(last_n)
	while last_n != last_n_rev:
		last_n += last_n_rev
		last_n_rev = digits_reversed(last_n)
		steps += 1
	return steps


palindrome_chain_length = lambda n: (lambda rev: 0 if n == rev(n) else palindrome_chain_length(n + rev(n)) + 1)(lambda n: int(''.join(list(reversed(str(n))))))


def reverse_int(n: int) -> int:
	return int(str(n)[::-1])

def palindrome_chain_length(n: int, i: int=0) -> int:
	return i if reverse_int(n) == n else palindrome_chain_length(n + reverse_int(n), i + 1)


def palindrome_chain_length(n):
	n = str(n)
	if n == n[::-1]:
		return 0
	return 1 + palindrome_chain_length(int(n) + int(n[::-1]))


def palindrome_chain_length(n):
	a = 0
	while 1:
		if n == int(str(n)[::-1]):
			return a
		else:
			n += int(str(n)[::-1])
		a += 1


def palindrome_chain_length(n):
	(num, s) = (0, str(n))
	while s != s[::-1]:
		num += 1
		s = str(int(s) + int(s[::-1]))
	return num


def palindrome_chain_length(n):
	cnt = 0
	while str(n) != str(n)[::-1]:
		n = n + int(str(n)[::-1])
		cnt = cnt + 1
	return cnt


import math

def is_palindrome(n):
	rev = 0
	num = n
	while n > 0:
		dig = math.floor(n % 10)
		rev = rev * 10 + dig
		n = math.floor(n / 10)
	return True if num == rev else False

def reverse(n):
	if n < 0:
		return None
	rev = 0
	while n > 0:
		dig = math.floor(n % 10)
		rev = rev * 10 + dig
		n = math.floor(n / 10)
	return rev

def palindrome_chain_length(n):
	step = 0
	while not is_palindrome(n):
		n += reverse(n)
		step += 1
	return step


palindrome_chain_length = lambda n, c=0: (lambda pal: c if n == pal else palindrome_chain_length(n + pal, c + 1))(int(str(n)[::-1]))


def palindrome_chain_length(n):
	is_palindrome = lambda x: str(x) == str(x)[::-1]
	res = 0
	while not is_palindrome(n):
		n += int(str(n)[::-1])
		res += 1
	return res


def is_palindrome(n):
	string = str(n)
	reverse = int(''.join(reversed(string)))
	if n == reverse:
		return True
	else:
		return False

def palindrome_chain_length(n):
	i = 0
	while True:
		if is_palindrome(n):
			break
		else:
			n += int(''.join(reversed(str(n))))
		i += 1
	return i


def palindrome_chain_length(n):
	count = 0
	num = str(n)
	rev_num = str(n)[::-1]
	sum = 0
	while num != rev_num:
		num = str(int(num) + int(rev_num))
		rev_num = num[::-1]
		count += 1
	return count


def palindrome_chain_length(n):
	sum = 0
	count = 0
	print('The number is ' + str(n))
	new_num = str(n)[::-1]
	if str(n) == str(n)[::-1]:
		return 0
	else:
		while str(n) != str(sum):
			sum = n + int(new_num)
			n = sum
			new_num = str(sum)[::-1]
			sum = int(new_num)
			count += 1
		return count


def palindrome_chain_length(n):
	steps = 0
	if str(n) == str(n)[::-1]:
		return steps
	else:
		while str(n) != str(n)[::-1]:
			n += int(str(n)[::-1])
			steps += 1
	return steps


def palindrome_chain_length(n):
	pal = False
	c = 0
	while not pal:
		if str(n) == str(n)[::-1]:
			return c
		else:
			n = int(n + int(str(n)[::-1]))
			c += 1


palindrome_chain_length = lambda n: 0 if str(n) == str(n)[::-1] else (lambda l: ([None for i in iter(lambda : (([None for l[1] in [l[1] + int(str(l[1])[::-1])]], [None for l[0] in [l[0] + 1]]), str(l[1])[::-1] != str(l[1]))[1], False)], l[0])[1])({0: 0, 1: n})


def palindrome_chain_length(n):
	step = 0
	while str(n)[:] != str(n)[::-1]:
		n += int(str(n)[::-1])
		step += 1
	return step


def is_palindrome(n):
	return str(n) == str(n)[::-1]

def palindrome_chain_length(n):
	out = 0
	while not is_palindrome(n):
		out += 1
		n += int(str(n)[::-1])
	return out


def is_palindrome(v):
	return str(v) == str(v)[::-1]

def palindrome_chain_length(n):
	cnt = 0
	if is_palindrome(n):
		return cnt
	while True:
		cnt += 1
		n = n + int(str(n)[::-1])
		if is_palindrome(n):
			return cnt


def palindrome_chain_length(n):
	count = 0
	check = str(n)
	while check != check[::-1]:
		print(check)
		print(count)
		count += 1
		check = str(int(check) + int(check[::-1]))
	return count


def palindrome_chain_length(n):
	a = n
	r = 0
	while a != int(str(a)[::-1]):
		a += int(str(a)[::-1])
		r += 1
	return r


def palindrome_chain_length(n):
	strn = str(n)
	if strn == strn[::-1]:
		return 0
	else:
		count = 0
		value = strn
		while value[::-1] != value:
			value = str(int(value[::-1]) + int(value))
			count += 1
		return count


def palindrome_chain_length(n):
	run = 0
	word = str(n)
	revers = word[::-1]
	while word != revers:
		word = str(int(word) + int(word[::-1]))
		revers = word[::-1]
		run += 1
	return run


def is_palindrome(n):
	return str(n) == str(n)[::-1]

def palindrome_chain_length(n):
	if is_palindrome(n):
		return 0
	step = 0
	while not is_palindrome(n):
		rev = int(str(n)[::-1])
		n = n + rev
		step += 1
	return step


def palindrome_chain_length(n):
	x = list(str(n))
	result = 0
	while x != x[::-1]:
		n = n + int(''.join(x[::-1]))
		x = list(str(n))
		result += 1
	return result


def palindrome_chain_length(total):
	counter = 0
	reverse_total = str(total)[::-1]
	while total != int(reverse_total):
		total = total + int(reverse_total)
		reverse_total = str(total)[::-1]
		counter += 1
	return counter


def palindrome_chain_length(n):
	c = 0
	rev = int(str(n)[::-1])
	while n != rev:
		n = n + rev
		rev = int(str(n)[::-1])
		c += 1
	return c


def palindrome_chain_length(x):

	def f(x):
		return str(int(x) + int(''.join(list(reversed(x)))))

	def isPalindrome(s):
		return s == s[::-1]
	n = 0
	x = str(x)
	while True:
		if isPalindrome(x):
			return n
		else:
			x = f(x)
			n = n + 1


def palindrome_chain_length(n):
	count = 0
	while True:
		rev = int(str(n)[::-1])
		if n == rev:
			return count
		else:
			n += rev
			count += 1


def palindrome_chain_length(n):
	c = 0
	if str(n) != str(n)[::-1]:
		while str(n) != str(n)[::-1]:
			n += int(str(n)[::-1])
			c += 1
		return c
	else:
		return 0


def palindrome_chain_length(n):
	c = 0
	rn = int(str(n)[::-1])
	while rn != n:
		n += rn
		rn = int(str(n)[::-1])
		c += 1
	return c


def palindrome_chain_length(n):
	level = 0
	while n != int(str(n)[::-1]):
		n += int(str(n)[::-1])
		level += 1
	return level


def palindrome_chain_length(n):
	s = str(n)
	s_rev = s[::-1]
	count = 0
	while s != s[::-1]:
		temp = int(s)
		rev = int(s[::-1])
		test = temp + rev
		s = str(test)
		count += 1
	return count


def palindrome_chain_length(n):
	n = str(n)
	nreverserd = n[::-1]
	count = 0
	if n == nreverserd:
		return 0
	else:
		while True:
			count += 1
			sum = int(n) + int(nreverserd)
			n = str(sum)
			nreverserd = n[::-1]
			if n == nreverserd:
				break
	return count


def palindrome_chain_length(n):
	reverse = int(str(n)[::-1])
	length = 0
	while n != reverse:
		n += reverse
		reverse = int(str(n)[::-1])
		length += 1
	return length


def is_palindrome(x):
	return str(x) == str(x)[::-1]

def palindrome_chain_length(n):
	counter = 0
	while not is_palindrome(n):
		n = n + int(str(n)[::-1])
		counter += 1
	return counter


def palindrome_chain_length(n):
	n1 = int(str(n)[::-1])
	return 0 if n == n1 else 1 + palindrome_chain_length(n + n1)


def is_palindrome(n):
	return n == reverse_n(n)

def reverse_n(n):
	return int(str(n)[::-1])

def palindrome_chain_length(n):
	chain_n = 0
	while is_palindrome(n) is False:
		n = n + reverse_n(n)
		chain_n += 1
	return chain_n


def IsPalindrome(n):
	if str(n) == str(n)[::-1]:
		return True
	return False

def palindrome_chain_length(n):
	result = 0
	while not IsPalindrome(n):
		n = n + int(str(n)[::-1])
		result += 1
	return result


def palindrome_chain_length(n, cr=0):
	while str(n) != str(n)[::-1]:
		(n, cr) = (n + int(str(n)[::-1]), cr + 1)
	return cr


def is_palindrome(n):
	return str(n) == str(n)[::-1]

def palindrome_chain_length(n):
	c = 0
	while not is_palindrome(n):
		(a, b) = (n, int(str(n)[::-1]))
		n = a + b
		c += 1
	return c


def is_palindrome(n):
	n = str(n)
	if len(n) % 2:
		return n[:len(n) // 2] == n[len(n) // 2 + 1:][::-1]
	else:
		return n[:len(n) // 2] == n[len(n) // 2:][::-1]

def palindrome_chain_length(n):
	if n < 10:
		return 0
	if is_palindrome(n):
		return 0
	else:
		i = 0
		while not is_palindrome(n):
			i += 1
			n = n + int(str(n)[::-1])
		return i


def palindrome_chain_length(n):
	if str(n) == str(n)[::-1]:
		return 0
	(res, count) = (n, 0)
	while True:
		count += 1
		res += int(str(res)[::-1])
		if str(res) == str(res)[::-1]:
			return count
	return count


def palindrome_chain_length(n):
	n = str(n)
	if int(n) == int(str(n)[::-1]):
		return 0
	else:
		s = int(n) + int(n[::-1])
		count = 1
		while s != int(str(s)[::-1]):
			s = s + int(str(s)[::-1])
			count += 1
		return count


def palindrome_chain_length(n):
	step = 0
	while True:
		r = reverse(n)
		if n == r:
			break
		n += r
		step += 1
	return step

def reverse(n):
	ans = 0
	while n > 0:
		ans = 10 * ans + n % 10
		n //= 10
	return ans


def palindrome_chain_length(n):
	s = str(n)
	for i in range(0, 50):
		if s == s[::-1]:
			return i
		else:
			s = str(int(s) + int(s[::-1]))


def palindrome_chain_length(n):
	number = n
	i = 0
	while i < 10000:
		number = str(number)
		if number == number[::-1]:
			return i
		else:
			number = int(number) + int(number[::-1])
			i = i + 1


def palindrome_chain_length(n):
	return [4, 0, 0, 24, 1][[87, 1, 88, 89, 10].index(n)]


def palindrome_chain_length(n):
	n_str = str(n)
	steps = 0
	while n_str != n_str[::-1]:
		steps += 1
		palindrome = int(n_str) + int(n_str[::-1])
		n_str = str(palindrome)
	return steps


def palindrome_chain_length(n):
	pal = int(str(n)[::-1])
	res = 0
	while n != pal:
		n += pal
		pal = int(str(n)[::-1])
		res += 1
	return res


def palindrome_chain_length(n, s=0):
	if str(n) == str(n)[::-1]:
		return s
	else:
		return palindrome_chain_length(n + int(str(n)[::-1]), s + 1)


def palindrome_chain_length(n):
	answer = []
	pal = int(str(n)[::-1])
	while n != pal:
		n += pal
		pal = int(str(n)[::-1])
		answer.append(n)
	return len(answer)


def palindrome_chain_length(n):
	loop = 0
	while str(n) != str(n)[::-1]:
		n += int(str(n)[::-1])
		loop += 1
	return loop