Skip to content

Instantly share code, notes, and snippets.

@nbyouri
Created January 2, 2017 10:56
Show Gist options
  • Save nbyouri/ca21ae1648ff70c1c349d5e5b8fcea34 to your computer and use it in GitHub Desktop.
Save nbyouri/ca21ae1648ff70c1c349d5e5b8fcea34 to your computer and use it in GitHub Desktop.
Small Julia utilities for counting
# C(n,r)
function C(n::Int, r::Int)
return (factorial(n)) / (factorial(r)*factorial(n - r))
end
# P(n,r)
function P(n::Int, r::Int)
return (factorial(n) / factorial(n -r))
end
# Sum of a function in a j .. n range
function ∑(j::Int, n::Int, f::Function)
ans = 0
for i = j : n
ans += f(n, i)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment