Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Recursive Solution solution in Clear category for Domino Chain by Tinus_Trotyl
def trailes(tile_a, tiles):
n=0
if not tiles: return 1
for i, tile_b in enumerate(tiles):
match = tile_a & tile_b
if match: n += trailes(tile_b - match if tile_b - match else tile_b, tiles[:i] + tiles[i+1:])
return n
def domino_chain(tiles: str) -> int:
n, tiles = 0, [set(int(i) for i in j.split("-")) for j in tiles.replace(" ", "").split(",")]
for i, tile in enumerate(tiles): n += trailes(tile, tiles[:i] + tiles[i+1:])
return n//2
Aug. 28, 2017
Comments: