finished algorithm for the even up calulation