algorithm exercise code