Evaluate binomial coefficients: Difference between revisions
Content added Content deleted
(→Functional Applescript: Added a reduced variant of the main function) |
|||
Line 254: | Line 254: | ||
factorial(n) div (factorial(n - k) * (factorial(k))) |
factorial(n) div (factorial(n - k) * (factorial(k))) |
||
end binomialCoefficient |
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: | Line 266: | ||
on run |
on run |
||
binomialCoefficient(5, 3) |
{binomialCoefficient(5, 3), binomialCoefficient2(5, 3)} |
||
--> 10 |
--> {10, 10} |
||
end run |
end run |
||
Line 316: | Line 323: | ||
end product</lang> |
end product</lang> |
||
{{Out}} |
{{Out}} |
||
<pre>10</pre> |
<pre>{10, 10}</pre> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |