作者:lys焦糖布丁cj_625 | 来源:互联网 | 2023-06-30 17:13
篇首语:本文由编程笔记#小编为大家整理,主要介绍了ruby recursive_methods.rb相关的知识,希望对你有一定的参考价值。
#Output: number of possible teams
def choose_team(n, k)
return n if k == 1
return 0 if k == 0 || n == 0
choose_team(n-1,k-1) + choose_team(n-1,k)
end
p choose_team(6,1) == 6
p choose_team(6,2) == 15
p choose_team(6,3) == 20
p choose_team(24,4) == 10626