the triple differences solution algorithm