done the candy algrithm