Domino algorithm