Solution for homework