algo3: hw6: problem3 almost finished