Evaluate binomial coefficients: Difference between revisions

→‎{{header|Ruby}}: Added Array.combination.size
(Undo revision 216802 by Grondilu (talk) oops, actually not. My bad.)
(→‎{{header|Ruby}}: Added Array.combination.size)
Line 1,574:
(0...r).inject(1) do |m,i| (m * (n - i)) / (i + 1) end
end
</lang>Ruby's Arrays have a combination method which result in a (lazy) enumerator. This Enumerator has a "size" method, which returns the size of the enumerator, or nil if it can’t be calculated lazily. (Since Ruby 2.0)
</lang>
<lang ruby>(1..60).to_a.combination(30).size #=> 118264581564861424</lang>
 
=={{header|Run BASIC}}==
1,149

edits