Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import wraps
- from time import time
- import numpy as np
- def timeit(func):
- @wraps(func)
- def wrapper(*args, **kwargs):
- s = time()
- ret = func(*args, **kwargs)
- e = time()
- print(f'{func.__name__} used: {e-s} seconds.')
- return ret
- return wrapper
- def get_path(arr, last_index=0, last_ret=1):
- if last_index==len(arr)-1 or last_ret==0:
- yield last_ret
- return
- for step in (1, 2):
- if last_index + step >= len(arr):
- continue
- yield from get_path(arr, last_index + step, last_ret*arr[last_index + step])
- @timeit
- def get_max(arr):
- return max(get_path(arr))
- if __name__ == '__main__':
- n = 50
- ns = np.random.randint(-10,10,(n,))
- print(get_max(ns))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement