I'm afraid you haven't demonstrated anything in your question to show how you would solve this problem, and you've asked the monastary to either write your code, or provide a link to code. Monks reply like so:
Is PM a good place to get answers for homework?
That being said, you can start with the tutorials section here.
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday