A **bouncy number** is a positive integer whose digits neither increase nor decrease. For example, `1235` is an increasing number, `5321` is a decreasing number, and `2351` is a bouncy number. By definition, all numbers under `100` are non-bouncy, and `101` is the first bouncy number. To complete this kata, you must write a function that takes a number and determines if it is bouncy.

Input numbers will always be positive integers, but it never hurts to throw in some error handling : )

For clarification, the bouncy numbers between `100` and `125` are: `101, 102, 103, 104, 105, 106, 107, 108, 109, 120, and 121`.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def is_bouncy(number):
	

Solutions:
def is_bouncy(n):
	return sorted(str(n)) != list(str(n)) and sorted(str(n)) != list(str(n))[::-1]


def is_bouncy(n):
	s = str(n)
	decrease = increase = False
	for (a, b) in zip(s, s[1:]):
		if a < b:
			increase = True
		elif a > b:
			decrease = True
	return decrease and increase


def is_bouncy(number):
	return sorted(str(number)) != list(str(number)) != sorted(str(number))[::-1]


def is_bouncy(n):
	lst = list(map(int, str(n)))
	return {1, -1} <= {(b < a) - (b > a) for (a, b) in zip(lst, lst[1:])}


def is_bouncy(number):
	n = str(number)
	return not sorted(n) == list(n) and (not sorted(n, reverse=True) == list(n))


def is_bouncy(number):
	string = str(number)
	sort = ''.join(sorted(string))
	reverse = ''.join(reversed(string))
	return sort != string and sort != reverse


def is_bouncy(number):
	n = str(number)
	s = ''.join(sorted(n))
	return s != n != s[::-1]


def is_bouncy(n):
	num_list = [int(x) for x in str(n)]
	up = down = False
	for index in range(1, len(num_list)):
		if num_list[index - 1] < num_list[index]:
			up = True
		elif num_list[index - 1] > num_list[index]:
			down = True
		if up and down:
			return True
	return False