Advertisement
uzunovz

Softuniada 2017 - 01. Sum to 13

Jan 11th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. # Group equal sums
  2. # Read 3 numbers check if sum 13
  3. # Change only signs
  4.  
  5. result = False
  6.  
  7. checkMatrix = [
  8.     [-1, -1, -1],
  9.     [-1, -1, 1],
  10.     [-1, 1, -1],
  11.     [1, -1, -1],
  12.     [-1, 1, 1],
  13.     [1, 1, -1],
  14.     [1, 1, 1]
  15. ]
  16.  
  17. numbers = input().split(' ')
  18.  
  19. for num in range(len(numbers)):
  20.     numbers[num] = abs(int(numbers[num]))
  21.  
  22. if sum(numbers) == 13:
  23.     result = True
  24. else:
  25.     for minus in checkMatrix:
  26.         current_sum = sum([a * b for a, b in zip(numbers, minus)])
  27.         if abs(current_sum) == 13:
  28.             result = True
  29.             break
  30.  
  31. if result:
  32.     print("Yes")
  33. else:
  34.     print("No")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement