# Eulerian number or Euler triangle

**URL:** <https://discourse.julialang.org/t/eulerian-number-or-euler-triangle/98304>\
**Category:** General Usage\
**Created:** [May 4, 2023, 8:29am UTC](https://discourse.julialang.org/t/eulerian-number-or-euler-triangle/98304 "2023-05-04T08:29:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephans3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephans3/32/34552_2.png) [@stephans3](https://discourse.julialang.org/u/stephans3)\
**Post date:** [May 4, 2023, 8:29am UTC](https://discourse.julialang.org/t/eulerian-number-or-euler-triangle/98304/1 "2023-05-04T08:29:33Z")

</div>

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](https://en.wikipedia.org/wiki/Eulerian_number)

My **recursive algorithm**

```julia
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

```julia
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 🙂
