Evaluate binomial coefficients: Difference between revisions

CoffeeScript
(Added BBC BASIC)
(CoffeeScript)
Line 289:
(let [rprod (fn [a b] (reduce * (range a (inc b))))]
(/ (rprod (- n k -1) n) (rprod 1 k))))</lang>
 
=={{header|CoffeeScript}}==
<lang coffeescript>
binomial_coefficient = (n, k) ->
result = 1
for i in [0...k]
result *= (n - i) / (i + 1)
result
n = 5
for k in [0..n]
console.log "binomial_coefficient(#{n}, #{k}) = #{binomial_coefficient(n,k)}"
</lang>
 
output
<lang>
> coffee binomial.coffee
binomial_coefficient(5, 0) = 1
binomial_coefficient(5, 1) = 5
binomial_coefficient(5, 2) = 10
binomial_coefficient(5, 3) = 10
binomial_coefficient(5, 4) = 5
binomial_coefficient(5, 5) = 1
</lang>
 
=={{header|Common Lisp}}==
Anonymous user