(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 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)