[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ์์์ฐพ๊ธฐ / Python
๐ Problem Solving/Programmers
import sys
from itertools import permutations
input = sys.stdin.readline
numbers = input().rstrip()
def isPrime(n):
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def solution(numbers):
answer = []
for i in range(len(numbers)):
temp = list(set((map(int, map("".join, permutations(numbers, i + 1))))))
print(temp)
for n in temp:
if isPrime(n):
answer.append(n)
return len(set(answer))
print(solution(numbers))
ํด์ค
permutations๋ฅผ ํตํด ๋ชจ๋ ์กฐํฉ์ ์ถ์ถํ๊ณ set์ผ๋ก ์ค๋ณต๋๋ ๊ฐ์ ์ ๊ฑฐํ๋ค.
๊ทธ๋ ๊ฒ ์ป๋ ๋ฐ์ดํฐ๋ฅผ isPrime ํจ์๋ฅผ ํตํด ์์ ํ์ ์ ํ ๋ค, ์์์ด๋ฉด answer์ ์ถ๊ฐํ๋ค.
answer์ ์ค๋ณต ๊ฐ์ ์ ๊ฑฐํ๊ธฐ ์ํด set์ ์ด์ฉํ๊ณ answer์ ๊ธธ์ด๋ฅผ ๋ฆฌํดํ๋ค.
'๐ Problem Solving > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ์นดํซ / Python (0) | 2021.06.14 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ๊ฐ์ฅ ํฐ ์ / Python (0) | 2021.06.14 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ์กฐ์ด์คํฑ / Python (0) | 2021.06.02 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ํ๋ฆฐํฐ / Python (0) | 2021.06.02 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ์ ํ๋ฒํธ ๋ชฉ๋ก / Python (0) | 2021.06.02 |