Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export bellnum,
legendresymbol,
lucasnum,
stirlings1,
stirlings2
stirlings2,
dealnnoy

"""
bellnum(n)
Expand Down Expand Up @@ -166,3 +167,29 @@ function stirlings2(n::Int, k::Int)

return k * stirlings2(n - 1, k) + stirlings2(n - 1, k - 1)
end

"""
Delannoy number describes the number of paths from the southwest corner (0, 0) of a rectangular grid
to the northeast corner (m, n), using only single steps north, northeast, or east
"""
function dealnnoy(m::Integer,n::Integer)
if m<0
throw(DomainError(m, "m must be nonnegative"))
end
if n<0
throw(DomainError(n, "n must be nonnegative"))
end
A = ones(BigInt, m+1, n+1)
for i = 1:m+1
A[i,1] = 1
end
for i = 1:n+1
A[1,i] = 1
end
for i = 2:m+1
for j = 2:n+1
A[i,j] = A[i-1,j] + A[i-1,j-1] + A[i,j-1]
end
end
return(A[m+1,n+1])
end
5 changes: 5 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
@test lobbnum(50,100) == parse(BigInt,"303574146822833458064977353764024400258025594128")
@test_throws DomainError lobbnum(-1,2)

#Delannoy
@test dealnnoy(3,4) == 129
@test dealnnoy(4,5) == 681
@test_throws DomainError dealnnoy(-1,2)

# narayana
@test narayana(8,5) == 490
@test narayana(100,50) == parse(BigInt, "99794739256977899071474889425225225330079579752931446368")
Expand Down