Create a function `close_compare` that accepts 3 parameters: `a`, `b`, and an optional `margin`. The function should return whether `a` is lower than, close to, or higher than `b`. `a` is "close to" `b` if `margin` is higher than or equal to the difference between `a` and `b`.

When `a` is lower than `b`, return `-1`.

When `a` is higher than `b`, return `1`.

When `a` is close to `b`, return `0`.

If `margin` is not given, treat it as zero.

Example: if `a = 3`, `b = 5` and the `margin = 3`, since `a` and `b` are no more than 3 apart, `close_compare` should return `0`. Otherwise, if instead `margin = 0`, `a` is lower than `b` and `close_compare` should return `-1`.

Assume: `margin >= 0`

Tip: Some languages have a way to make arguments optional.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def close_compare(a, b, margin=0):
	

Solutions:
def close_compare(a, b, margin=0):
	return 0 if abs(a - b) <= margin else -1 if b > a else 1


def close_compare(a, b, margin=0):
	if a == b or abs(a - b) <= margin:
		return 0
	if a < b:
		return -1
	if a > b:
		return 1


def close_compare(a, b, margin=0):
	if a - b > margin:
		return 1
	elif b - a > margin:
		return -1
	else:
		return 0


def close_compare(a, b, margin=0):
	if abs(a - b) <= margin:
		return 0
	return (a > b) - (a < b)


close_compare = lambda a, b, margin=0: 0 if abs(a - b) <= margin else -1 if a < b else 1


def close_compare(a, b, margin=0):
	return abs(a - b) > margin and (a > b) - (a < b)


from numpy import sign

def close_compare(a, b, margin=0):
	return abs(a - b) > margin and sign(a - b)


close_compare = lambda a, b, m=0: 0 if abs(a - b) <= m else -1 * (a < b) + (a > b)


def close_compare(a, b, margin=0):
	if abs(a - b) <= margin:
		return 0
	elif a < b:
		return -1
	return 1


def close_compare(a, b, margin=0):
	return a - b > margin or -(a - b < -margin)


def close_compare(a, b, margin=0):
	return (2 * (a > b) - 1) * (abs(a - b) > margin)


def close_compare(a, b, m=0):
	return [(a > b) - (a < b), 0][abs(a - b) <= m]


def close_compare(a, b, m=0):
	return 0 if abs(a - b) <= m else (a > b) - (a < b)


def close_compare(a, b, m=0):
	return -1 if m + a < b else [0, 1][m + b < a]


close_compare = lambda a, b, m=0: (a + m >= b) - (a - m <= b)


def close_compare(a, b, margin=None):
	if margin is not None:
		if round(abs(a - b), 3) <= margin:
			return 0
	if a < b:
		return -1
	elif a > b:
		return 1
	return 0


def close_compare(a, b, margin=0):
	x = a - b
	if margin >= abs(x):
		return 0
	elif x < 0:
		return -1
	else:
		return 1


def close_compare(a, b, margin=None):
	if margin == None:
		margin = 0
	result = a - b
	if margin >= abs(result):
		return 0
	elif result > 0:
		return 1
	else:
		return -1


def close_compare(a, b, margin=0):
	if max(a, b) - min(a, b) <= margin:
		return 0
	if a > b:
		return 1
	return -1


def close_compare(a, b, margin=0):
	marginal = abs(a - b)
	if margin >= marginal:
		return 0
	if a < b:
		return -1
	if a > b:
		return 1
print(close_compare(2, 8))
pass


def close_compare(a, b, margin=0):
	plus = a + margin
	minus = a - margin
	if plus > b and minus > b:
		return 1
	elif plus < b and minus < b:
		return -1
	else:
		return 0


def close_compare(a, b, margin=0):
	difference = abs(a - b)
	if margin >= difference:
		return 0
	elif a > b:
		return 1
	elif a < b:
		return -1
	pass


def close_compare(a, b, margin=0):
	if a < b and abs(a - b) > margin:
		return -1
	elif a == b or abs(a - b) <= margin:
		return 0
	else:
		return 1


import math

def close_compare(a, b, margin=0):
	if -margin <= a - b <= margin:
		return 0
	return 1 if a > b else -1


def close_compare(a, b, margin=0):
	if margin is not 0 and abs(a - b) <= margin or a == b:
		return 0
	else:
		return -1 if a < b else 1


def close_compare(a, b, margin=0):
	if margin == 0:
		if a == b:
			return 0
		elif a > b:
			return 1
		elif a < b:
			return -1
	elif margin > 0:
		if a - b > 0 and a - b <= margin:
			return 0
		elif a - b < 0 and (a - b) * -1 == margin:
			return 0
		elif a - b < 0 and (a - b) * -1 <= margin:
			return 0
		elif a == b:
			return 0
		elif a > b:
			return 1
		elif a - b < 0 and a - b <= margin:
			return -1


def close_compare(a, b, margin=0):
	l = range(b - margin, b + margin + 1)
	if a in l:
		return 0
	elif a < b:
		return -1
	else:
		return 1


import math

def close_compare(a, b, margin=0):
	if math.fabs(a - b) <= margin:
		return 0
	if a < b:
		return -1
	return 1


def close_compare(a, b, m=0):
	d = a - b
	if abs(d) <= m:
		return 0
	return d / abs(d)


def close_compare(a, b, margin=0):
	compare = 0
	if margin != 0:
		if a < b and b - a <= margin:
			compare = 0
			return compare
		if a < b and b - a > margin:
			compare = -1
			return compare
		if a == b:
			compare = 0
			return compare
		if a > b and a - b <= margin:
			compare = 0
			return compare
		if a > b and a - b > margin:
			compare = 1
			return compare
	else:
		if a < b:
			compare = -1
			return compare
		if a > b:
			compare = 1
			return compare
		if a == b:
			compare = 0
			return compare


close_compare = lambda a, b, c=0: ((a > b) - (b > a)) * (abs(a - b) > c)


def close_compare(a, b, margin=0):
	if margin >= ((a - b) ** 2) ** 0.5:
		return 0
	return 1 if a > b else -1


def close_compare(a, b, margin=0):
	if a in range(b - margin, b + margin + 1):
		return 0
	if a > b + margin:
		return 1
	if a < b + margin:
		return -1


def close_compare(a, b, margin=0):
	area = range(b - margin, b + 1 + margin)
	if a in area:
		return 0
	elif a < b - margin:
		return -1
	elif a > b + margin:
		return 1


def close_compare(a, b, margin=None):
	if not margin:
		return -1 if b > a else a > b
	return -1 if b - margin > a else a - margin > b


def close_compare(a, b, margin=0):
	adiff = abs(a - b)
	if adiff <= margin:
		return 0
	alist = sorted([a, b])
	if alist[0] == a:
		return -1
	else:
		return 1


def close_compare(a, b, margin=0):
	if a >= b:
		res = a - margin
		if res <= b:
			return 0
		else:
			return 1
	if a <= b:
		ress = b - margin
		if ress <= a:
			return 0
		else:
			return -1


def close_compare(a, b, margin=0):
	c = abs(a - b)
	if c <= margin:
		return 0
	elif a > b:
		return 1
	else:
		return -1
	pass


def close_compare(a, b, *args):
	if args:
		if abs(a - b) <= args[0]:
			return 0
	if a == b:
		return 0
	return -1 if a - b < 0 else 1


def close_compare(a, b, margin=0):
	return -1 if a + margin < b else int(a - margin > b)


def close_compare(a, b, margin=0):
	if a == b:
		r = 0
	if a < b:
		r = -1
	if a > b:
		r = 1
	if abs(a - b) <= margin:
		r = 0
	return r