250x250
Link
๋‚˜์˜ GitHub Contribution ๊ทธ๋ž˜ํ”„
Loading data ...
Notice
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Data Science LAB

[Python] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - level1(๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„) ๋ณธ๋ฌธ

๐Ÿ“ Coding Test/Programmers

[Python] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - level1(๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„)

ใ…… ใ…œ ใ…” ใ…‡ 2022. 8. 26. 15:14
728x90

1. ๋ฌธ์ œ

 

๋ฌธ์ œ ์š”์•ฝ : 0 ์ธ ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ๋ชจ๋ฅด๋Š” ๋ฒˆํ˜ธ, ์Šน๋ฆฌ๋ฒˆํ˜ธ์™€ ์ผ์น˜ํ•˜๋Š” ์ตœ์†Œ ๊ฐœ์ˆ˜์™€ ์ตœ๋Œ€ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•ด์„œ ๋“ฑ์ˆ˜๋กœ ๋ณ€ํ™˜ํ•ด์•ผํ•จ

 

 

2. ์ œํ•œ์‚ฌํ•ญ

 

 

 

3. ๋‚ด ํ’€์ด

def solution(lottos, win_nums):
    answer = []
    unknown = lottos.count(0)
    score = []
    for i in lottos:
        if i in win_nums:
            score.append(i)
            
    min_score = len(score)
    max_score = unknown + min_score
    
    answer = [max_score, min_score]
    answer = list(map(lambda x: 7-x if x > 0 else 6, answer))
    return answer

 

1. ๋‚ด๊ฐ€ ์‚ฐ ๋ณต๊ถŒ์˜ 0 ์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ธ์คŒ -> ๋ชจ๋ฅด๋Š” ๋ฒˆํ˜ธ์˜ ๊ฐœ์ˆ˜ ์นด์šดํŠธ

2. ์ด๊ธด ๋ฒˆํ˜ธ์™€ ๋Œ€์กฐํ•ด ์ผ์น˜ํ•˜๋Š” ๊ฐœ์ˆ˜ ์นด์šดํŠธ

3.  ๋งž์ถ˜ ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ตœ์†Œ ๊ฐœ์ˆ˜ : ์ด๋ฏธ ์ผ์น˜๋œ ๊ฐœ์ˆ˜,  / ์ตœ๋Œ€ ๊ฐœ์ˆ˜ : ์ด๋ฏธ ์ผ์น˜๋œ ๊ฐœ์ˆ˜  + 0(์•Œ์ˆ˜ ์—†๋Š” ๋ฒˆํ˜ธ)์˜ ๊ฐœ์ˆ˜ (๋‹ค ๋งž์•˜๋‹ค๊ณ  ๊ฐ€์ •)

4. lambda ํ•จ์ˆ˜ ์ด์šฉํ•ด ์ ์ˆ˜ ๋ฐ˜ํ™˜ (7์—์„œ ๋งž์ถ˜ ๊ฐœ์ˆ˜ ๋นผ์ฃผ๊ณ  0 ์ด๋ฉด 6์œผ๋กœ ๋ฐ˜ํ™˜)

 

 

4. ๋‹ค๋ฅธ ์‚ฌ๋žŒ ํ’€์ด

def solution(lottos, win_nums):

    rank=[6,6,5,4,3,2,1]

    cnt_0 = lottos.count(0)
    ans = 0
    for x in win_nums:
        if x in lottos:
            ans += 1
    return rank[cnt_0 + ans],rank[ans]

 

์ ‘๊ทผ ๋ฐฉ์‹์€ ๋น„์Šทํ•˜์ง€๋งŒ rank๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๋ฐ›์•„์„œ ๋“ฑ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜์˜€๊ณ , ๋ฆฌ์ŠคํŠธ๊ฐ€ ์•„๋‹Œ ์ˆซ์ž๋ฅผ 1์”ฉ ๋”ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์งœ์…จ๋‹ค.

 

def solution(lottos, win_nums):
    rank = {
        0: 6,
        1: 6,
        2: 5,
        3: 4,
        4: 3,
        5: 2,
        6: 1
    }
    return [rank[len(set(lottos) & set(win_nums)) + lottos.count(0)], rank[len(set(lottos) & set(win_nums))]]

 

๋‘๋ฒˆ์งธ ํ’€์ด๋Š” rank๋ฅผ ๋”•์…”๋„ˆ๋ฆฌ๋กœ ๋ฐ›์•„์„œ ๋ฐ˜ํ™˜ํ•˜๊ณ , ๊ต์ง‘ํ•ฉ์œผ๋กœ ๋งž์ถ˜ ๋ฒˆํ˜ธ์˜ ๊ฐœ์ˆ˜๋ฅผ ์นด์šดํŠธํ•˜์…จ๋‹ค.

 

์„ธ์ƒ์—” ๋˜‘๋˜‘ํ•œ์‚ฌ๋žŒ์ด ๋„ˆ๋ฌด ๋งŽ์•„...๐Ÿ˜

728x90
Comments