pikaliov

Recursion test

Mar 18th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. """
  2. """
  3. def func_rec(M, N):
  4.     """
  5.    recursion func which describe function Anckerman
  6.    M, N : input values in func
  7.    """
  8.     assert (M >= 0 and N >= 0), 'M and N is equal or greater than zero'
  9.     if M == 0:
  10.         return (N + 1)
  11.     elif M > 0 and N == 0:
  12.         return func_rec(M-1, 1)
  13.     elif M > 0 and N > 0:
  14.         return func_rec(M-1, func_rec(M, N-1))
  15.    
  16. def main_func():
  17.     """
  18.    main funct to entry recursion func
  19.    """
  20.     M = int(input('M_val -->: '))
  21.     N = int(input('N_val -->: '))
  22.     assert (M <= 3 and N <= 3), 'input M and N is equal or less than 3 due to complexity'
  23.     res = func_rec(M, N)    # result of func
  24.     print(res)
  25.  
  26. if __name__ == "__main__":
  27.     main_func()
Advertisement
Add Comment
Please, Sign In to add comment