Talk:Special factorials: Difference between revisions

→‎Reverse factorial algorithm: Fixed syntax highlighting
(→‎Reverse factorial algorithm: Fixed syntax highlighting)
 
(One intermediate revision by one other user not shown)
Line 1:
=== 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.
<syntaxhighlight lang="java">
<lang java>public static int rf(int n) {
if (n == 1)
return 0; //1 has two answers -- return the lower one
Line 14 ⟶ 15:
return b;
else return -1; //undefined
}</lang>
</syntaxhighlight>
--[[User:Chunes|Chunes]] ([[User talk:Chunes|talk]]) 17:06, 16 March 2021 (UTC)
 
Line 27 ⟶ 29:
: I think it's just that the formula literally produces 0 for n = 0.
: First run through, i is 1, this produces -1. Second run through, i is 0, this produces 1 and their sum is 0. --[[User:Chunes|Chunes]] ([[User talk:Chunes|talk]]) 17:36, 16 March 2021 (UTC)
 
So the math summation notation goes backwards automatically when i > n? This may make a good task -- C will do one iteration and stop, etc. --[[User:Wherrera|Wherrera]] ([[User talk:Wherrera|talk]]) 21:11, 16 March 2021 (UTC)
3,043

edits