Skip to content

Commit dce89da

Browse files
author
Alfredo Miranda
committed
Completed close_far.py
1 parent e671dad commit dce89da

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

python/logic-2/close_far.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Given three ints, a b c, return True if one of b or c is "close" (differing
2+
# from a by at most 1), while the other is "far", differing from both other
3+
# values by 2 or more.
4+
def close_far(a, b, c):
5+
return (is_close(a, b) and is_far(a, b, c)) or \
6+
(is_close(a, c) and is_far(a, c, b))
7+
8+
def is_close(a, b):
9+
return abs(a - b) <= 1
10+
11+
def is_far(a, b, c):
12+
return abs(a - c) >= 2 and abs(b - c) >= 2

0 commit comments

Comments
 (0)