Skip to content

Instantly share code, notes, and snippets.

@nathanPro
Created August 8, 2015 15:43
Show Gist options
  • Save nathanPro/95f5706c2fdf78217f17 to your computer and use it in GitHub Desktop.
Save nathanPro/95f5706c2fdf78217f17 to your computer and use it in GitHub Desktop.
PD com combinações em ruby
$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