Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Digits Doublets solution in Uncategorized category for Digits Doublets by capback250
# migrated from python 2.7
import re
def make_matrix(array):
n = {}
for x in array:
n[x] = []
for number in array:
for matcher in array:
if number == matcher:
pass
elif re.search(repr(matcher)[0]+'\d'+repr(matcher)[2], repr(number)) or repr(matcher)[:-1] in repr(number) or repr(matcher)[1:] in repr(number):
n[number].append(matcher)
print(n)
return n
def bfs(graph, start, end):
# maintain a queue of paths
queue = []
# push the first path into the queue
queue.append([start])
while queue:
# get the first path from the queue
path = queue.pop(0)
# get the last node from the path
node = path[-1]
# path found
if node == end:
return path
# enumerate all adjacent nodes, construct a new path and push it into the queue
for adjacent in graph.get(node, []):
new_path = list(path)
new_path.append(adjacent)
queue.append(new_path)
def checkio(array):
return bfs(make_matrix(array), array[0], array[-1])
Oct. 18, 2015