Pandaaaa906

find_max_point

Jun 14th, 2020
1,002
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from functools import wraps
  2. from time import time
  3.  
  4. import numpy as np
  5.  
  6.  
  7. def timeit(func):
  8.     @wraps(func)
  9.     def wrapper(*args, **kwargs):
  10.         s = time()
  11.         ret = func(*args, **kwargs)
  12.         e = time()
  13.         print(f'{func.__name__} used: {e-s} seconds.')
  14.         return ret
  15.     return wrapper
  16.  
  17.  
  18. def get_path(arr, last_index=0, last_ret=1):
  19.     if last_index==len(arr)-1 or last_ret==0:
  20.         yield last_ret
  21.         return
  22.     for step in (1, 2):
  23.         if last_index + step >= len(arr):
  24.             continue
  25.         yield from get_path(arr, last_index + step, last_ret*arr[last_index + step])
  26.  
  27. @timeit
  28. def get_max(arr):
  29.     return max(get_path(arr))
  30.  
  31. if __name__ == '__main__':
  32.     n = 50
  33.     ns = np.random.randint(-10,10,(n,))
  34.     print(get_max(ns))
RAW Paste Data