in reply to SEEKING HELP
I would first write out the method you would use by hand and then try to turn sentences into code.
Is this perchance homework? Because there is no need of math to solve it.