Evaluate binomial coefficients: Difference between revisions
→Functional Applescript: Added a reduced variant of the main function
(→Functional Applescript: Added a reduced variant of the main function) |
|||
Line 254:
factorial(n) div (factorial(n - k) * (factorial(k)))
end binomialCoefficient
-- Or, by reduction:
-- binomialCoefficient2 :: Int -> Int -> Int
on binomialCoefficient2(n, k)
product(enumFromTo(1 + k, n)) div (factorial(n - k))
end binomialCoefficient2
Line 259 ⟶ 266:
on run
{binomialCoefficient(5, 3), binomialCoefficient2(5, 3)}
--> {10, 10}
end run
Line 316 ⟶ 323:
end product</lang>
{{Out}}
<pre>{10, 10}</pre>
=={{header|AutoHotkey}}==
|