๐Ÿ—๏ธ Algorithm/โฌ› ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

โฌ› [Programmers] [Python] [2018 KAKAO BLIND RECRUITMENT] [Level2] [3์ฐจ] n์ง„์ˆ˜ ๊ฒŒ์ž„

Dbswnstjd 2023. 4. 17. 12:27

๋ฌธ์ œ

https://school.programmers.co.kr/learn/courses/30/lessons/17687

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

ํ’€์ด

# ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - n์ง„์ˆ˜ ๊ฒŒ์ž„
def convert(n, base):
    arr = '0123456789ABCDEF'
    q, r = divmod(n, base)
    if q == 0:
        return arr[r]
    else:
        return convert(q, base) + arr[r]
def solution(n, t, m, p):
    answer = ''
    candidate = []
    
    for i in range(t*m):
        conv = convert(i, n)
        for c in conv:
            candidate.append(c)
    
    for i in range(p-1, t*m, m):
        answer += candidate[i]
        
    return answer

n์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” convert ํ•จ์ˆ˜๋ฅผ ์žฌ๊ท€๋ฅผ ํ†ตํ•ด ๊ตฌํ˜„ํ•˜์˜€๋‹ค.