first attempt at problem 1 full solution