Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Domino Chain by mozurin
def domino_chain(tiles):
memo = {}
def recurse(current, tiles):
key = (current, tiles)
if key not in memo:
memo[key] = sum(
sum(
recurse(p, tiles - set([tile]))
for p in set(tile) - set([current]) or [current]
) for tile in tiles if current is None or current in tile
) if tiles else 1
return memo[key]
return recurse(
None,
frozenset(tuple(tile.strip().split('-')) for tile in tiles.split(','))
) // 2
July 27, 2018