This is his friend's solution, who passed barely, with a 2. I've doctored it up to grade 4 at his place, so he could see how to solve such tasks.