Is there a cleaner way to solve these problems?

10 / 18