re-made solution to problem 2 after accidentally deleting it