• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 23rd, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # ifac
2. def ifac(n):
3.   product = 1
4.   for i in range(1, n+1):
5.     product *= i
6.   return product
7.
8. import sys
9. sys.setrecursionlimit(10000)
10.
11. # rfac
12. def rfac(n):
13.   if n == 0:
14.     return 1
15.   else:
16.     return n * rfac(n-1)
17.
18. # perm
19. def perm(n, r):
20.   return ifac(n)//ifac(n-r)
21.
22. # comb
23. def comb(n, r):
24.   return ifac(n) // (ifac(r)*ifac(n-r))
25.
26. # fib
27. def fib(n):
28.   if n == 1 or n == 2:
29.     return 1
30.   else:
31.     return fib(n-1) + fib(n-2)
32.
33.
34. # mfib
35. fibd = {}
36. def mfib(n):
37.   if n in fibd:
38.     return fibd[n]
39.   elif n == 0:
40.     return 0
41.   elif n == 1:
42.     return 1
43.   else:
44.     sum = mfib(n-1) + mfib(n-2)
45.     fibd[n] = sum
46.     return sum
47.
48. # pascal
49. def pascal(row, col):
50.   if col == 0:
51.     return 1
52.   elif row == col:
53.     return 1
54.   else:
55.     return pascal(row-1, col-1) + pascal(row-1, col)
56.
57. # mpascal
58. pasd = {}
59. def mpascal(row, col):
60.   if (row, col) in pasd:
61.     return pasd[(row, col)]
62.   elif col == 0:
63.     return 1
64.   elif row == col:
65.     return 1
66.   else:
67.     sum = mpascal(row-1, col-1) + mpascal(row-1, col)
68.     pasd[(row, col)] = sum
69.     return sum
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?