programmers | Lv2. ์†Œ์ˆ˜ ์ฐพ๊ธฐ [Python]

yeonkยท2022๋…„ 2์›” 26์ผ
0

algorithm

๋ชฉ๋ก ๋ณด๊ธฐ
48/88
post-thumbnail

๐Ÿ’ก Python 3






๐Ÿ”— ๋ฌธ์ œ

์†Œ์ˆ˜ ์ฐพ๊ธฐ [Link]






๐Ÿ’ป ์ฝ”๋“œ

def solution(n):
    from itertools import permutations
    nl = []
    for r in range(1, len(n)+1):
        per = list(permutations(n, r))
        nl += [int(''.join(p)) for p in per]   
        
    nl = set(nl)
    count = 0
    
    for nm in nl: 
        if nm == 0 or nm == 1: 
            count += 1
            continue
        for i in range(2, int(nm**0.5) + 1):
            if  nm % i == 0: 
                count += 1 
                break
    return len(nl) - count






๐Ÿ’ฅ ๋‹ค๋ฅธ ์‚ฌ๋žŒ ์ฝ”๋“œ

set ์—ฐ์‚ฐ์ž ๊ธฐ์–ตํ•˜์ž.. |ํ•ฉ์ง‘ํ•ฉ, & ๊ต์ง‘ํ•ฉ, - ์ฐจ์ง‘ํ•ฉ, ^ ๋Œ€์นญ ์ฐจ์ง‘ํ•ฉ

from itertools import permutations
def solution(n):
    a = set()
    for i in range(len(n)):
        a |= set(map(int, map("".join, permutations(list(n), i + 1))))
    a -= set(range(0, 2))
    for i in range(2, int(max(a) ** 0.5) + 1):
        a -= set(range(i * 2, max(a) + 1, i))
    return len(a)






์ฐธ๊ณ  ์ž๋ฃŒ

18. set(์ง‘ํ•ฉ)

0๊ฐœ์˜ ๋Œ“๊ธ€