Create a gist now

Instantly share code, notes, and snippets.

@yukirin /
Last active Aug 29, 2015

What would you like to do?
Python functools.lru_cacheで竹内関数をメモ化
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from functools import lru_cache
import time
def tarai(x, y, z):
if x <= y: return y
return tarai(
tarai(x - 1, y, z),
tarai(y - 1, z, x),
tarai(z - 1, x, y))
st_time = time.clock()
tarai(12, 6, 0)
print(time.clock() - st_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment