itteratvie binary search worked well, written by rosseta code