refactor problem 3
fix prob4 output