File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ ## 처음 풀이 - combination를 이용한 풀이
2+
3+ from itertools import combinations
4+
5+ def solution (nums ):
6+ answer = 0
7+ sosu = combinations (nums ,3 )
8+ for i in [sum (i ) for i in sosu ]:
9+ for j in range (2 ,i ):
10+ if i % j == 0 :
11+ break
12+ else : answer += 1
13+ return answer
14+
15+ ## 안 좋았던 풀이 - for문 이용
16+ def sosu (_num ) :
17+ if _num > 1 :
18+ for i in range (2 ,_num ):
19+ if _num % i == 0 :
20+ return False
21+ else :
22+ return True
23+
24+ def solution (nums ):
25+ answer = 0
26+ for i in range (len (nums )):
27+ for j in range (i + 1 ,len (nums )):
28+ for k in range (j + 1 ,len (nums )):
29+ _num = nums [i ]+ nums [j ]+ nums [k ]
30+ if sosu (_num ) == True :
31+ answer += 1
32+ return answer
33+
34+
35+ ## 2번째 풀이
36+ from itertools import combinations
37+ import math ;
38+
39+ def sosu (_num ):
40+ # n의 최대 약수가 sqrt(n) 이하이므로 i=sqrt(n)까지 검사
41+ i = int (math .sqrt (_num ))
42+ divisior = [i for i in range (1 , m + 1 ) if n % i == 0 ]
43+
44+ return len (divisior ) == 1
45+
46+ def solution (nums ):
47+ sosu_num = list (combinations (nums , 3 ))
48+ enables = list (filter (lambda n : sosu (n [0 ] + n [1 ] + n [2 ]), sosu_num ))
49+
50+ return len (enables )
Original file line number Diff line number Diff line change 1+ def solution (nums ):
2+
3+ mySet = set (nums )
4+ if len (mySet ) > int (len (nums )/ 2 ) :
5+ return int (len (nums )/ 2 )
6+ return len (mySet )
You can’t perform that action at this time.
0 commit comments