읽어보면 그냥 조합(combination) 구현하라는 소리. 내 머릿속에서 보통 암산하는 조합푸는 방법 그대로 구현하였다. 마지막에 팩토리얼수로 나누어주어야 하는데 팩토리얼도 효율적으로 코딩 가능하긴한데 귀찮아서 그냥 math모듈 import해서 사용. 점점 자료구조형과 실제 수학공식을 알고 있어야 하는 문제들 등장 중.
import math
def solution(balls, share): #조합계산 하세요
comb_1 = balls
comb_2 = share
if (comb_1 - comb_2) < comb_2:
comb_2 = (comb_1 - comb_2)
count = 1
for i in range(comb_2):
count *= (comb_1 - i)
count = count / math.factorial(comb_2)
return count