aboutsummaryrefslogtreecommitdiff
path: root/challenge-085/paulo-custodio/python/ch-1.py
blob: 54f9e1cd1b80236952f237f4057b56dcc496e76b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3

# Challenge 085
#
# TASK #1 > Triplet Sum
# Submitted by: Mohammad S Anwar
# You are given an array of real numbers greater than zero.
#
# Write a script to find if there exists a triplet (a,b,c) such that
# 1 < a+b+c < 2. Print 1 if you succeed otherwise 0.
#
# Example 1:
# Input: @R = (1.2, 0.4, 0.1, 2.5)
# Output: 1 as 1 < 1.2 + 0.4 + 0.1 < 2
# Example 2:
# Input: @R = (0.2, 1.5, 0.9, 1.1)
# Output: 0
# Example 3:
# Input: @R = (0.5, 1.1, 0.3, 0.7)
# Output: 1 as 1 < 0.5 + 1.1 + 0.3 < 2

import sys
from itertools import combinations

def check(nums):
    for combin in combinations(nums, 3):
        if 1.0 < sum(combin) < 2.0:
            return True
    return False

print(1 if check([float(x) for x in sys.argv[1:]]) else 0)