diff options
Diffstat (limited to 'challenge-199/ealvar3z/python/ch-2.py')
| -rw-r--r-- | challenge-199/ealvar3z/python/ch-2.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-199/ealvar3z/python/ch-2.py b/challenge-199/ealvar3z/python/ch-2.py new file mode 100644 index 0000000000..1ed0a2c97e --- /dev/null +++ b/challenge-199/ealvar3z/python/ch-2.py @@ -0,0 +1,21 @@ +from itertools import combinations + + +def solve(arr, a, b, c): + total = 0 + for i,j,k in combinations(arr,3): + if ((abs(i-j) <= a) and + (abs(j-k) <= b) and + (abs(i-k) <= c)): + total += 1 + return total + + +if __name__ == '__main__': + test1 = [3, 0, 1, 1, 9, 7] + test2 = [1, 1, 2, 2, 3] + a, b, c = [7, 2, 3] + d, e, f = [0, 0, 1] + + print("Output: ", solve(test1, a, b, c)) + print("Output: ", solve(test2, d, e, f)) |
