my attempt at solving the problem