implementation of the up-right algorithm discussed in http://asherv.com/threes/threemails/#letter