My solution to codility problem of September