# Little off-coding but a question đ¤

A challenge test says: `factorialize(0)` should return 1. Can anyone give a simple straightforward explanation of why 0! or zero factorial is equal to 1?

You are referring to the recursion question right?

Ok yeah.

So yeah this is more of a math question but it is always used for recursion coding challenges.

Math is fun has a pretty simple explanation.

Hope that helps!

1 Like

This is a fairly good explanation:

Not sure itâs as simple as you would like though

1 Like

Itâs a convenience I guess? Someone better at maths could explain this, but afaik itâs because you can multiply exponents in maths. And for that to work properly 0 has to equal 1. If it equalled 0, then multiplying by 0 also equals 0 and it would prevent it working (x^2 Ă x^0 needs to equal x^2, not 0)

Edit: Iâve just read an explanation similar to the one in the link above that makes sense to me. You use factorials to calculate how many unique permutations of something there can be, and the formula is `n!/k!(k - n)!` (ânumber of ways of choosing n things from a collection of k thingsâ).

So if you want to see how many people can shake hands in a group of n people, k is 2 (2 people shake hands). If there are only 2 people (n is also 2), then obviously there can be only 1 handshake, but to calculate it using the formula:

``````2! / 2!(2 - 2)!
2! / 2!0!
2! / 2!
2 / 2
1
``````

If 0! equalled 0, then that would mean the division would be

``````2 / 0
``````

Which wouldnât be correct.

(Edit2: it still doesnât quite make it clear to me how a mathematician can just sorta wave their hands and go âletâs just make this equal 1, itâll make the other sums workâ, I donât know enough about maths to understand why doing that doesnât matter. I suspect my knowledge of multiplication is stuck at very basic high school level and in fact Iâm slightly misunderstanding what multiplication actually does)

3 Likes

After knowing @JeremyLT for 17 years, I still struggle with this.

1 Like

The glib answer - it is needed for all of the math to work

My favorite way to think about factorial numbers in that `n!` means âhow many different ways can I arrange `n` balls of different colorsâ.

Suppose I have 3 balls, `['red', 'yellow', 'blue']`.

There are `n! = 3 * 2 * 1 = 6` ways for me to arrange these balls:
`['red', 'yellow', 'blue']`
`['red', 'blue', 'yellow']`
`['yellow', 'red', 'blue']`
`['yellow', 'blue', 'red']`
`['blue', 'red', 'yellow']`
`['blue', 'yellow', 'red']`

From this you can see, this ball arranging definition makes sense, because I have `3` choices for my first ball. Once Iâve picked my first ball, I have `2` choices for my second ball, and after that I have `1` choice for my remaining ball. Thatâs a total of `6` different ball arrangements.

This pattern works for any number of balls.

Now, how many different ways can you arrange `0` balls?

âŚ

Exactly `1` way! You do nothing, and that is the only possible arrangement.

Looking back at the glib answer now, this âball arranging logicâ shows up in a lot of deep mathematical logic, and this logic only works out right if we consistently use the idea that there is only `1` way to arrange `0` balls (or the equivalent statement for the various deep mathematical logic statements under consideration).

3 Likes

@DanCouper

there was also this other, with fractions

``````5! / 5 = 4!
4! / 4 = 3!
3! / 3 = 2!
2! / 2 = 1!
1! / 1 = 0!
``````

the only way to make this last line true is if 0! equals 1, as on the left hand side there is 1/1

2 Likes