binomial_theorem.sf 228 B

123456789101112
  1. #!/usr/bin/ruby
  2. # Simple implementation of the binomial theorem.
  3. func binomial_sum(a, b, n) {
  4. sum(0..n, {|k|
  5. binomial(n, k) * a**(n-k) * b**k
  6. })
  7. }
  8. say binomial_sum(3, 5, 10) #=> 1073741824 (= (3+5)^10)