solution to problem 1
shortened the solution
solution to problem 2