Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # from http://www.senktec.com/2013/09/one-way-to-do-it/
- def f1(n):
- if n > 1:
- return n * f1(n - 1)
- else:
- return 1
- def f2(n):
- return n * f2(n - 1) if n > 1 else 1
- def f3(n):
- if n <= 1: return 1
- else: return f3(n - 1) * n
- def f4(n, accumulator=1):
- if n == 0:
- return accumulator
- else:
- return f4(n - 1, accumulator * n)
- f5 = lambda n: n and n * f5(n - 1) or 1
- def f6(n):
- result = 1
- for i in range(1, n + 1):
- result *= i
- return result
- def f7(n):
- result = 1
- while n > 0:
- result *= n
- n -= 1
- return result
- def f8(n):
- if n == 0:
- return 1
- else:
- return reduce(lambda a,b: a * b, range(1, n + 1))
- def f9(n):
- numbers = xrange(1, n + 1)
- if len(numbers) == 0:
- return 1
- return reduce(int.__mul__, numbers)
- def f10(n):
- if n == 0: return 1
- return eval('*'.join([str(i) for i in range(1, n + 1)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement