Skip to content

Instantly share code, notes, and snippets.

@foota
Last active December 14, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foota/5127840 to your computer and use it in GitHub Desktop.
Save foota/5127840 to your computer and use it in GitHub Desktop.
Sample code for timeit module. Tarai and factorial functions.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def tarai(x, y, z):
return tarai(tarai(x - 1, y, z),
tarai(y - 1, z, x),
tarai(z - 1, x, y)) if x > y else y
def factorial(n):
return n == 0 and 1 or reduce(lambda x, y: x * y, range(1, n + 1))
def main():
print tarai(12, 6, 0) # Tarai(12, 6, 0)
print factorial(10) # 10!
if __name__ == "__main__": main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment