Talk:Special factorials: Difference between revisions
Content added Content deleted
(Demonstrate an efficient, readable reverse factorial algorithm) |
(question) |
||
Line 13: | Line 13: | ||
}</lang> |
}</lang> |
||
--[[User:Chunes|Chunes]] ([[User talk:Chunes|talk]]) 17:06, 16 March 2021 (UTC) |
--[[User:Chunes|Chunes]] ([[User talk:Chunes|talk]]) 17:06, 16 March 2021 (UTC) |
||
=== Why is af(0) 0? === |
|||
Is it that 0 is the additive identity the way that factorial of 0 is 1 is the multiplicative identity? If so why should it be the identity anyway? |
Revision as of 17:25, 16 March 2021
Reverse factorial algorithm
I took a stab at translating the reverse factorial algorithm used in the Factor entry to Java. It should be almost as efficient as taking the factorial itself. <lang java>public static int rf(int n) {
int a = 1; int b = 1; while (n > a) { b++; a = a * b; } if (a == n) return b; else return -1; //undefined }</lang>
--Chunes (talk) 17:06, 16 March 2021 (UTC)
Why is af(0) 0?
Is it that 0 is the additive identity the way that factorial of 0 is 1 is the multiplicative identity? If so why should it be the identity anyway?