finished problem 3
implemented solution for p4