JuliaMath / Combinatorics.jl

A combinatorics library for Julia
http://juliamath.github.io/Combinatorics.jl/dev/
Other
214 stars 58 forks source link

Handle n=0,1 for hyperfactorial #105

Closed scheinerman closed 2 years ago

scheinerman commented 3 years ago

The value of the hyperfactorial function for both 0 and of 1 is 1. Should be easy to add these as special cases.

julia> hyperfactorial(0)
ERROR: ArgumentError: reducing over an empty collection is not allowed

julia> hyperfactorial(1)
ERROR: ArgumentError: reducing over an empty collection is not allowed
logankilpatrick commented 2 years ago

Hey @scheinerman, if you want to make a PR to address this, I can happily review it since you are right, it should return 1 in both cases.

scheinerman commented 2 years ago

Hi @logankilpatrick , I am OK at coding by really don't understand at all how git works! But I suppose we just replace this

hyperfactorial(n::Integer) = prod(i->i^i, BigInt(2):n)

with this

hyperfactorial(n::Integer) = (n==0) ? BigInt(1) : prod(i->i^i, BigInt(1):n)

I know how to edit my own code, but not other people's!