A robot is initially in the square (0,0). The robot then moves step by step according to a given sequence of commands. The sequence consists of the symbols U
(up), D
(down), L
(left) and R
(right). How many distinct squares does the robot visit?
You may assume that the sequence contains at most 10^5 commands.
In a file robot.py
, implement a function count
that is given the sequence of commands and returns the number of distinct squares.
def count(s): # TODO if __name__ == "__main__": print(count("LL")) # 3 print(count("UUDLRR")) # 5 print(count("UDUDUDU")) # 2