Add groups of same gems search algorithm