final soltuion for week 3 exercise