Files
exercism_puzzles/python/secret-handshake/secret_handshake.py
T

25 lines
851 B
Python

def commands(binary_str):
list_of_commands: list = [
0,
"jump",
"close your eyes",
"double blink",
"wink",
]
order_of_commands: list = []
reverse_flag: bool = False
for index, code in enumerate(binary_str):
# if code is a '1', append the corresponded command to the order_of_commands
# unless the index is 0: in that case set the reverse_flag to True
# keep in mind i am searching for commands from left to right, so the order
# of commands is already reversed
if code == "1":
if index == 0:
reverse_flag = True
else:
order_of_commands.append(list_of_commands[index])
# do i want to keep it reversed?
if not reverse_flag:
order_of_commands.reverse()
return order_of_commands