Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
for...elif...elfor solution in Clear category for Color Map by veky
def adjacent(region):
for row in region:
for a, b in zip(row, row[1:]):
if a != b: yield frozenset({a, b})
def color_map(region):
edges = set(adjacent(region)).union(adjacent(zip(*region)))
N1 = max(set().union(*region))
def colorings(colors):
n1 = len(colors) - 1
last = colors[n1]
for i, color in enumerate(colors):
if {i, n1} in edges and color == last: return
if n1 == N1: yield colors
else:
for c in 1, 2, 3, 4: yield from colorings(colors + [c])
return next(colorings([1]))
July 21, 2017
Comments: