|
Minimizing command string program
Hi i have been given this program as an assignement:
There is a robot, which accepts ONLY these 2 commands S to go straight one m
etre and R to turn left! The robot draws lines on the floor when it moves.
You are asked to write a program so that it will receive a string of command
s and give you the minimum string that will produce the same drawing!
*Assume that the robot always starts from the point (0,0) and the initial co
mmand string cannot be more than 1000 commands long.
i.e:
1) You are given the command string {s,s,r,r,s,s}.
The minimum command is {s,s}
2) You are given the command {r,r,r,r,r,r,r}
The minimum command is {}
3) You are given the command {r,r,r,r,r,r,s}
The minimum command is {r,r,s}
I've written a program that passes the whole "drawing" to a graph (an array
with the movements) and starts with a null string and continue adding comman
ds and testing all the possible combinations.
It works but it's not good towards it's complexity...
Any help for an algorythm or something appreciated!
Thanks
__________________
|