Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Color Map by TovarischZhukov
# migrated from python 2.7
def find(dct_data, colors, ln):
if len(colors)==ln: return colors
for key in dct_data:
r=[1,2,3,4]
for val in dct_data[key]:
if val in colors and colors[val] in r: r.remove(colors[val])
for val in r:
n_colors=colors.copy()
n_colors[key]=val
n_dct_data=dct_data.copy()
del n_dct_data[key]
ret = find(n_dct_data, n_colors, ln)
if ret: return ret
def color_map(data):
dct_data={}; colors={}
for i,el in enumerate(data):
for j,val in enumerate(el):
if val not in dct_data: dct_data[val]=set()
if j+1=0 and el[j-1]!=val: dct_data[val].add(el[j-1])
if i+1=0 and data[i-1][j]!=val: dct_data[val].add(data[i-1][j])
return list(find(dct_data, colors, len(dct_data)).values())
Feb. 9, 2016