If you define the problem correctly, you almost have the solution.