Algorithm for Bergson Matches logic game