submitted hw 17, but having trouble, need help with algorithm