In this article we see the solution of Question 6. of Section B.
The solution would be simple, as per syllabus standard not very much abstracted and verbose but it will pretty straight forward.
You can easily copy the code by clicking on copy button ...