Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Digits Doublets by Moff
class Solver(object):
def __init__(self, chain):
self.min_chain = chain
self.target = chain[-1]
self.find_path([chain[0]], chain[1:])
@staticmethod
def dist(n1, n2):
return sum(1 for a, b in zip(str(n1), str(n2)) if a != b)
def find_path(self, path, rest):
if path[-1] == self.target and len(path) < len(self.min_chain):
self.min_chain = path
return
n1 = path[-1]
for n2 in rest:
if self.dist(n1, n2) == 1:
self.find_path(path + [n2], [n for n in rest if n != n2])
def checkio(chain):
return Solver(chain).min_chain
Aug. 13, 2015