Hello.
First come up with a simple algorithm to solve your problem theoretically. You can do it by trial and error method.
Once you feel like the algorithm works correctly convert into a...