finished pseudocode
finished initial solution and it works!