Created
August 8, 2015 15:43
-
-
Save nathanPro/95f5706c2fdf78217f17 to your computer and use it in GitHub Desktop.
PD com combinações em ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$comb = Hash.new do |comb, n| | |
if n == 0 | |
comb[n] = Hash.new(0) | |
comb[0][0] = 1; | |
else | |
comb[n] = Hash.new do |hash, k| | |
if k == 0 | |
hash[k] = 1; | |
else | |
hash[k] = comb[n-1][k-1] + comb[n-1][k]; | |
end | |
end | |
end | |
end | |
puts $comb[100][3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment