fork download
  1. from itertools import combinations
  2.  
  3. def numOfPairs(q_len):
  4. result = 0
  5. comb = list(combinations(q, 2))
  6. for pair in comb:
  7. x, y = pair
  8. minima = min(abs(x), abs(y))
  9. maxima = max(abs(x), abs(y))
  10. op_minima = min(abs(x-y), abs(x+y))
  11. op_maxima = max(abs(x-y), abs(x+y))
  12.  
  13. if op_minima <= minima and op_maxima >= maxima:
  14. result += 1
  15. print(result)
  16.  
  17. q = [-9,6,-2,1]
  18. numOfPairs(q)
  19.  
Success #stdin #stdout 0.03s 9200KB
stdin
Standard input is empty
stdout
2