Happy algorithm exercise