Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
breadth-first search solution in Clear category for Digits Doublets by David_Jones
from collections import deque
from operator import ne as not_equal
def checkio(numbers):
successor = {}
queue = deque([numbers.pop()])
while queue:
u = queue.popleft()
if u == numbers[0]:
chain = []
while True:
chain.append(u)
if u not in successor:
return chain
u = successor[u]
for v in numbers:
if v not in successor and sum(map(not_equal, str(u), str(v))) < 2:
successor[v] = u
queue.append(v)
May 16, 2019
Comments: