코딩테스트 파이썬/파이썬 프로그래머스 1단계
주사위 게임 3
세용용용용
2023. 10. 28. 13:11



코딩테스트 연습 - 주사위 게임 3 | 프로그래머스 스쿨 (programmers.co.kr)
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
나의 코드
from collections import Counter
def solution(a, b, c, d):
answer = 0
game_list = [a,b,c,d]
# 주사위 딕셔너리 만들고 개수로 정렬
game = Counter(game_list)
game = dict(sorted(game.items(), key=lambda x:x[1], reverse=True))
print(game)
# 조건에따라 answer 처리해주자
if len(game) == 1:
answer = 1111*list(game.keys())[0]
elif len(game) == 2:
if max(list(game.values())) == 3:
answer = (10*list(game.keys())[0]+list(game.keys())[1])**2
elif max(list(game.values())) == 2:
answer = (list(game.keys())[0] + list(game.keys())[1]) * abs(list(game.keys())[0] - list(game.keys())[1])
elif len(game) == 3:
answer = list(game.keys())[1] * list(game.keys())[2]
else:
answer = min(list(game.keys()))
print(answer)
return answer