A robot moves as in the earlier task this week, but now repeats the same command sequence k times. How many distinct squares does the robot visit?
You may assume that the sequence has at most 100 commands, and that k is in the range 1 \dots 10^9
In a file longroute
, implement a function count
that returns the number of distinct squares visited when given the command sequence and the number of repetitions.
def count(s,k): # TODO if __name__ == "__main__": print(count("UR", 100)) # 201 print(count("UD", 100)) # 2 print(count("UURRDDL", 500)) # 1506 print(count("L", 10**9)) # 1000000001 print(count("DLUR", 10**9)) # 4