Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
BFS solution in Clear category for Digits Doublets by veky
def checkio(numbers):
import collections, operator
q, v = collections.deque({numbers.pop()}), {}
while q:
t = q.popleft()
if t == numbers[0]:
result = []
while True:
result.append(t)
try: t = v[t]
except KeyError: return result
for u in numbers:
if sum(map(operator.ne, str(t), str(u))) <= 1 and u not in v:
v[u] = t
q.append(u)
Feb. 11, 2014
Comments: