Hi all,
as I could not find an implementation for the Eulerian number / Eulerian triangle I developed it briefly.
There exists an recursive algorithm and an explicit formula. More infos could be found on Wikipedia:
https://en.wikipedia.org/wiki/Eulerian_number
My recursive algorithm
function euler_rec(n::Int64, k::Int64)
if n==0
if k==0
return 1
else
return 0
end
end
return (n-k) * big(euler_rec(n-1,k-1)) + (k+1)*big(euler_rec(n-1,k))
end
and my explicit (direct) formula is
function euler_dir(n::Int64, k::Int64)
igrid = 0 : 1 : k
a_int(i) = (-1)^(i) * big(binomial(n+1,i))*(big(k+1-i))^n
return mapreduce( i -> a_int(i), +, igrid)
end
I need to use BigInt
with big(...)
as return values because the return values increase dramatically.
Please feel free to improve or extend my code