Skip to content

Instantly share code, notes, and snippets.

@carolineartz
Forked from dbc-challenges/recursive_methods.rb
Last active August 29, 2015 13:57
Show Gist options
  • Save carolineartz/3f9ca0a32eb93f41eada to your computer and use it in GitHub Desktop.
Save carolineartz/3f9ca0a32eb93f41eada to your computer and use it in GitHub Desktop.
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment