Post Reply 
(42S) Subfactorial
09-07-2021, 02:21 PM
Post: #3
RE: (42S) Subfactorial
(09-06-2021 06:50 PM)John Keith Wrote:  A simpler formula for the first program is a(n) = (n-1)*(a(n-1) + a(n-2)). Maybe not as easy to implement with a 4-level stack because you have to keep the two previous values to compute the current one.

We can use https://mathworld.wolfram.com/Subfactorial.html, #5

!n = n * !(n-1) + (-1)^n

Code:
def subfac(n, r=0):     # integer n > 0
    for i in range(2,n+1): r = 1-i*r
    return abs(r)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(42S) Subfactorial - Eddie W. Shore - 09-06-2021, 04:43 PM
RE: (42S) Subfactorial - John Keith - 09-06-2021, 06:50 PM
RE: (42S) Subfactorial - Albert Chan - 09-07-2021 02:21 PM
RE: (42S) Subfactorial - Werner - 09-09-2021, 07:24 AM
RE: (42S) Subfactorial - Albert Chan - 09-09-2021, 03:33 PM
RE: (42S) Subfactorial - Albert Chan - 09-08-2021, 10:26 PM
RE: (42S) Subfactorial on HP-15C - C.Ret - 09-11-2021, 04:15 PM
RE: (42S) Subfactorial - Werner - 09-09-2021, 07:45 AM
RE: (42S) Subfactorial - Werner - 09-09-2021, 12:31 PM
RE: (42S) Subfactorial - ijabbott - 09-11-2021, 08:24 AM
RE: (42S) Subfactorial - Gil - 09-12-2021, 12:05 AM
RE: (42S) Subfactorial - Albert Chan - 09-12-2021, 12:46 PM
RE: (42S) Subfactorial - Matt Agajanian - 11-19-2024, 02:17 AM
RE: (42S) Subfactorial - Thomas Klemm - 11-19-2024, 04:32 AM
RE: (42S) Subfactorial - Thomas Klemm - 11-19-2024, 06:24 AM
RE: (42S) Subfactorial - Matt Agajanian - 11-21-2024, 01:31 AM
RE: (42S) Subfactorial - Thomas Klemm - 11-21-2024, 02:29 AM



User(s) browsing this thread: 1 Guest(s)