Created
March 24, 2023 19:33
-
-
Save jc3wrld999/cbe43d09a95b7703a1a1f22190e4fbda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def get_prime_number(numbers): | |
''' | |
프로그래머스 42839 소수 찾기(완전 탐색) | |
''' | |
answer = 0 | |
l = [n for n in numbers] | |
# 만들 수 있는 수 순열 만들기 | |
per = [] | |
for i in range(1, len(numbers)+1): | |
# per.extend(list(itertools.permutations(l, i))) | |
per += list(map("".join, itertools.permutations(l, i))) | |
new = list(set([int(p) for p in per if p[0] != '0'])) | |
# 그 수 중 소수 판별하기 | |
for n in new: | |
if n < 2: | |
continue | |
flag = True | |
for j in range(2, int(n**(1/2))+1): | |
if n % j == 0: | |
flag = False | |
break | |
if flag: | |
answer+=1 | |
return answer | |
get_prime_number('011') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment