Advertisement
OneTells

Untitled

May 21st, 2024
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. def ultra(base, count, command):
  2.     args = [base, count, command]
  3.     commands = [0]
  4.     result = []
  5.  
  6.     while commands:
  7.         command = commands.pop()
  8.  
  9.         if command == 0:
  10.             command_arg = args.pop()
  11.             count_arg = args.pop()
  12.             base_arg = args.pop()
  13.  
  14.             if command_arg == 1:
  15.                 commands.append(1)
  16.  
  17.                 result.append(base_arg)
  18.                 result.append(count_arg)
  19.                 continue
  20.  
  21.             if count_arg == 1:
  22.                 result.append(base_arg)
  23.                 continue
  24.  
  25.             commands.append(0)
  26.             args.append(base_arg)
  27.             args.append(command_arg - 1)
  28.  
  29.             commands.append(2)
  30.  
  31.             commands.append(0)
  32.             args.append(base_arg)
  33.             args.append(count_arg - 1)
  34.             args.append(command_arg)
  35.         elif command == 1:
  36.             result.append(result.pop() + result.pop())
  37.         elif command == 2:
  38.             r = result.pop()
  39.  
  40.             command_arg = args.pop()
  41.             args.append(r)
  42.             args.append(command_arg)
  43.  
  44.     return result.pop()
  45.  
  46.  
  47. print(ultra(2, 4, 4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement