Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Domino Chain by Dmitry_Sieroshtanov
def domino_chain(tiles: str) -> int:
l = list(tiles.split(", "))
result = set()
for unit in l:
x = l.pop(0)
comb = [x, x[::-1]]
for i in comb:
for n in l:
if i[~0] in n and n not in i and n[::-1] not in i:
if n.index(i[~0]):
comb.append(i + n[::-1])
else:
comb.append(i + ''.join(n))
l.append(x)
list(result.add(i) for i in comb if len(i) == len(l) * 3)
return len(result) // 2
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert domino_chain("0-2, 0-5, 1-5, 1-3, 5-5") == 1
assert domino_chain("1-5, 2-5, 3-5, 4-5, 3-4") == 2
assert domino_chain("0-5, 1-5, 2-5, 3-5, 4-5, 3-4") == 0
assert domino_chain("0-1, 0-2, 1-3, 1-2, 3-4, 2-4") == 6
assert domino_chain("0-1, 0-2, 1-3, 1-2, 3-4, 2-4, 3-0, 0-4") == 0
assert domino_chain("1-2, 2-2, 2-3, 3-3, 3-1") == 5
assert domino_chain("1-4, 3-4, 0-4, 0-5, 4-5, 2-4, 2-5") == 0
assert domino_chain("1-4, 1-5, 0-2, 1-6, 4-6, 4-5, 5-6") == 0
assert domino_chain("1-2, 2-3, 2-4, 3-4, 2-5, 2-6, 5-6") == 8
assert domino_chain("1-2, 2-3, 3-1, 4-5, 5-6, 6-4") == 0
assert domino_chain("1-2, 1-4, 1-5, 1-6, 1-1, 2-5, 4-6") == 28
print("Basic tests passed.")
Sept. 4, 2019
Comments: