Solve problem 112 and add custom cache decorator
This commit is contained in:
@@ -218,3 +218,15 @@ def is_permutation(n, p):
|
||||
for p_n in str(p):
|
||||
digit_counts_p[int(p_n)] += 1
|
||||
return digit_counts_n == digit_counts_p
|
||||
|
||||
|
||||
def cache(f):
|
||||
cache = {}
|
||||
def func_cached(*args):
|
||||
if args in cache:
|
||||
return cache[args]
|
||||
r = f(*args)
|
||||
cache[args] = r
|
||||
return r
|
||||
return func_cached
|
||||
|
||||
|
||||
Reference in New Issue
Block a user