final solution at hacktory #3