a not so pretty implementation of the three sum algorithm