summaryrefslogtreecommitdiff
path: root/algorithms/factorial.py
blob: 41eb70897a4164bdb11b579c77a38c20e5197d64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python2


cache = {0:1}

def fak(n):
    if n == 0: return 1
    if cache.get(n, 0):
       return cache[n]
    if not cache.get(n-1, 0):
        cache[n-1] = fak(n-1)
    return n*cache[n-1]

def fakn(n):
    if n == 0:
        return 1
    else:
        return n*fak(n-1)

for i in [fak(i) for i in reversed(range(10))]:
  print i