another solution for problem b