input
숫자
output
인풋으로 받은 숫자 중 세 수를 골라 더한 값이 소수이면 +1, +1이 몇번 되었는지 총합 return
리스트에서 세가지 수를 골라 더하는 법과 소수를 판별하는 함수를 만들지 못했다.
def check(a, b, c): total = a + b + c for i in range(2, total): if total % i == 0 : return False return True def solution(nums): answer = 0 for i in range(0, len(nums) - 2): for j in range(i+1, len(nums) - 1): for k in range(j+1, len(nums)): if check(nums[i], nums[j], nums[k]): answer += 1 return answer
combination활용
from itertools import combinations def check(a, b, c): total = a + b + c for i in range(2, total): if total % i == 0 : return False return True def solution(nums): answer = 0 A = list(combinations(nums, 3)) for i in A: if check(i[0], i[1], i[2]): answer += 1 return answer