RosettaCodeData/Task/Left-factorials/Sidef/left-factorials-3.sidef
2016-12-05 23:44:36 +01:00

18 lines
305 B
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

func left_fact(n) {
static cached = 0
static factorial = 1
static leftfact = 0
 
if (n < cached) {
cached = 0
factorial = 1
leftfact = 0
}
 
while (n > cached) {
leftfact += factorial
factorial *= ++cached
}
 
leftfact
}