basic manhattan algoritim