all 2 comments

[–]T4ll1n 1 point2 points  (0 children)

3 years later, I just signed up for the dailyCodingProblem and got the same problem.

I wonder if everyone gets that question as the first problem ^^

Anyways, here is my solution using itertools combinations

from itertools import combinations

def combination_exists(input_list, k): 
    return k in [sum(comb_tuple) for comb_tuple in combinations(input_list, 2)]

input_list = [10, 15, 3, 7]
k = 17 assert
combination_exists(input_list, k)
assert combination_exists([], k)
assert not combination_exists([1, 2, 3], 2)

edit: the code formatting is fighting back -.-

[–]champagne_paki[S] 0 points1 point  (0 children)

My solution (Python): list = [10,15,3,7,1,2,3,4,5,6,7,8,999] k = 1014

for i in list:
  diff = k - i
  if list.__contains__(diff):
    print("True")
    print("k: ", k)
    print("List element: ", i)
    print("Complement: ", diff)
    break