Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
11-liner: ain't nothin but stack solution in Clear category for Domino Chain by przemyslaw.daniel
def domino_chain(tiles):
tiles = [x.split('-') for x in tiles.split(', ')]
stack, result = [('', tiles)], 0
while stack:
last, tiles = stack.pop()
result += not tiles
for a, b in [(i, j) for i, j in tiles if last in i+j]:
tmp = [x for x in tiles if x != [a, b]]
stack += [(b, tmp)]*(last in a)
stack += [(a, tmp)]*(last in b and a != b)
return result//2
Sept. 8, 2017
Comments: