Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
stack solution in Creative category for Color Map by blabaster
from itertools import chain
def color_map(r):
i = max(chain(*r)) + 1
adjacent, stack = [set() for _ in range(i)], [0] * i
for l in chain(r, zip(*r)):
for p in zip(l, l[1:]):
if p[0] != p[1]:
adjacent[min(p)].add(max(p))
while i:
i -= 1
for stack[i] in range(stack[i] + 1, 5):
if all(stack[x] != stack[i] for x in adjacent[i]):
break
else:
stack[i] = 0
i += 2
return stack
Oct. 16, 2014
Comments: