Solution for the Codility Training questions