another solution for week 3's homework