More clever solution for problem 27