Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def ultra(base, count, command):
- args = [base, count, command]
- commands = [0]
- result = []
- while commands:
- command = commands.pop()
- if command == 0:
- command_arg = args.pop()
- count_arg = args.pop()
- base_arg = args.pop()
- if command_arg == 1:
- commands.append(1)
- result.append(base_arg)
- result.append(count_arg)
- continue
- if count_arg == 1:
- result.append(base_arg)
- continue
- commands.append(0)
- args.append(base_arg)
- args.append(command_arg - 1)
- commands.append(2)
- commands.append(0)
- args.append(base_arg)
- args.append(count_arg - 1)
- args.append(command_arg)
- elif command == 1:
- result.append(result.pop() + result.pop())
- elif command == 2:
- r = result.pop()
- command_arg = args.pop()
- args.append(r)
- args.append(command_arg)
- return result.pop()
- print(ultra(2, 4, 4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement