finish the number recongination algorithm