Solution for problem #36