Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- C++
- SW
- 매일메일
- 코딩테스트합격자되기
- Get
- 이코테
- json-server
- 프로그래머스
- JavaScript
- react-router
- createSlice
- redux
- sw expert academy
- 항해99
- 리액트
- 알고리즘
- 항해플러스
- react-redux
- redux-saga
- java
- programmers
- 자바
- Algorithm
- redux-toolkit
- Python
- maeil-mail
- useDispatch
- 테코테코
- react
- axios
Archives
- Today
- Total
Binary Journey
[프로그래머스] 소수찾기 본문
반응형
출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
from itertools import permutations
def solution(numbers):
answer = []
nums = [n for n in numbers]
per = []
for i in range(1, len(numbers)+1):
per += list(permutations(nums, i))
new_nums = [int(("").join(p)) for p in per]
for n in set(new_nums):
if n < 2:
continue
check = True
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
check = False
break
if check:
answer.append(n)
return len(answer)
* permutations 는 분리된 숫자들을 순열로 조합해주는 함수라고 한다.. 굿
참고: https://dev-note-97.tistory.com/99
반응형
'프로그래머스 > level 2' 카테고리의 다른 글
[프로그래머스] 피로도 (0) | 2022.08.06 |
---|---|
[프로그래머스] 큰 수 찾기 (0) | 2022.08.06 |
[프로그래머스] 카펫 (0) | 2022.07.07 |
[프로그래머스] H-Index (0) | 2022.06.30 |
[프로그래머스] 다리를 지나는 트럭 (0) | 2022.06.01 |