algorithm for sword referring to offer