my algorithm exercise