Solution for Problem #18