Partial solution to Week 2 homework