day 12, add nice color pictures
This commit is contained in:
parent
f05ac7a70f
commit
efc1f11758
|
@ -0,0 +1,58 @@
|
|||
import sys
|
||||
import networkx as netx
|
||||
|
||||
M = [ list(l) for l in sys.stdin.read().splitlines() ]
|
||||
H = len(M)
|
||||
W = len(M[0])
|
||||
START = tuple()
|
||||
END = tuple()
|
||||
G = netx.DiGraph()
|
||||
|
||||
for x in range(H):
|
||||
for y in range(W):
|
||||
k = (x,y)
|
||||
v = M[x][y]
|
||||
if v == 'S':
|
||||
START = k
|
||||
v = 'a'
|
||||
if v == 'E':
|
||||
END = k
|
||||
v = 'z'
|
||||
v = ord(v)
|
||||
for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)]:
|
||||
nx, ny = (x+dx, y+dy)
|
||||
if nx>=0 and nx<H and ny>=0 and ny<W:
|
||||
nk = (nx,ny)
|
||||
nv = M[nx][ny]
|
||||
if nv == 'S':
|
||||
nv = 'a'
|
||||
if nv == 'E':
|
||||
nv = 'z'
|
||||
nv = ord(nv)
|
||||
dv = nv - v
|
||||
if dv <=1: # can go down !
|
||||
G.add_edge(k,nk)
|
||||
|
||||
# palette by https://gka.github.io/palettes/#/26|s|ffffe5,fe9929,662506|ffffe0,ff005e,93003a|1|1
|
||||
C = [ '#ffffe5','#fff4d3','#ffeac1','#ffdfb0','#ffd49f','#fcca91','#f8c084','#f3b677','#edac6c','#e7a361','#e19a58','#da914e','#d38846','#cb803e','#c47737','#bc6f30','#b3672a','#ab5f24','#a3571f','#9a501a','#924816','#894112','#803a0e','#77330b','#6f2c09','#662506']
|
||||
c2i = lambda x: int("0x"+x,16)
|
||||
C = [ " ".join(map(str,map(c2i,[c[1:3],c[3:5],c[5:]]))) for c in C ]
|
||||
|
||||
for x in range(H):
|
||||
for y in range(W):
|
||||
v = M[x][y]
|
||||
if v == 'S':
|
||||
v = 'a'
|
||||
if v == 'E':
|
||||
v = 'z'
|
||||
M[x][y] = C[ord(v)-ord("a")]
|
||||
|
||||
S = netx.shortest_path(G, START, END)
|
||||
|
||||
print("P3")
|
||||
print("81 41")
|
||||
print("255")
|
||||
|
||||
for (x,y) in S:
|
||||
M[x][y] = "64 196 64"
|
||||
print("\n".join("\n".join(l) for l in M))
|
|
@ -0,0 +1,41 @@
|
|||
abcccccaaaccccaacaaccaaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccaaaaaa
|
||||
abcccccaaaacccaaaaaccaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccaaaa
|
||||
abcccccaaaaccaaaaaccccaaaccaaaaaacccacaaaaccccccccccccccccaaaccccccccccccccccaaaa
|
||||
abcccccaaacccaaaaaaccccccccaaaaaacccccaaccccccccccccccccccaaaccccccccccccccccaaaa
|
||||
abcccccccccccccaaaacccccccaaaaaaaaccccccccccccccccccccccccaaacccccccccccccccaaaaa
|
||||
abccccccaacccccaacccccccccaaaaaaaaccccccccccccccccccccccccaaaaccaaacccccccccccccc
|
||||
abccccccaacccccccccccccccaaacccaaaacccaacaaccccccccccacaccaaacaajaacccccccccccccc
|
||||
abcccaaaaaaaaccccacccccccaaaccccaaacccaaaaaccccccccccaaaaaaajjjjkkkccccccaacccccc
|
||||
abcccaaaaaaaacaaaacccccccccccccccccccaaaaaccccccccciiiijjjjjjjjjkkkkcaaaaaacccccc
|
||||
abcccccaaaacccaaaaaacccccccccccccccccaaaaaacccccciiiiiijjjjjjjrrrkkkkaaaaaaaacccc
|
||||
abcccccaaaaacccaaaacccccccccaacccccccccaaaaccccciiiiiiiijjjjrrrrrsskkaaaaaaaacccc
|
||||
abccccaaaaaaccaaaaacccccccccaaaacccccccaccccccciiiiqqqqrrrrrrrrrssskkkaaaaaaacccc
|
||||
abaaccaaccaaccaacaacccccccaaaaaaccccccccccccccciiiqqqqqrrrrrrruussskkkaaaaacccccc
|
||||
abaaaacccccccccccccccccccccaaaaccccccccaaaccccciiqqqqqttrrrruuuuussskkaaaaacccccc
|
||||
abaaaacccccccccccccccccccccaaaaaccccccccaaaaccchiqqqtttttuuuuuuuussskkcccaacccccc
|
||||
abaaacccccaaaccacccccccccccaacaaccccccaaaaaaccchhqqqtttttuuuuxxuussslllcccccccccc
|
||||
abaaaaccccaaaaaacaaccccccaccccccccccccaaaaacccchhqqqttxxxxuuxxyyusssllllccccccccc
|
||||
abacaaccccaaaaaacaaaaaaaaaaccccccccccccaaaaaccchhqqqttxxxxxxxxyuusssslllccccccccc
|
||||
abcccccccaaaaaaacaaaaaaaaaccccaacccccccaaccaccchhhqqtttxxxxxxyyvvvsssslllcccccccc
|
||||
abcccccccaaaaaaaaaaaaaaaaaccccaaaaccccccccccccchhhppqttxxxxxyyyvvvvsqqqlllccccccc
|
||||
SbcccaaccaaaaaaaaaaaaaaaaaacaaaaaacccccccccccchhhhpptttxxxEzzyyyyvvvqqqqlllcccccc
|
||||
abcccaaccccaaacaaaaaaaaaaaaacaaaaccccccccccccchhhppptttxxxyyyyyyyyvvvqqqlllcccccc
|
||||
abaaaaaaaacaaacaaaaaaaaaaaaacaaaaacaaccccccccchhpppsssxxyyyyyyyyvvvvvqqqlllcccccc
|
||||
abaaaaaaaaccccccccaaacaaaccccaacaaaaaccccccaagggpppsswwwwwwyyyvvvvvvqqqmmmmcccccc
|
||||
abccaaaaccccaacaacaaacaaacccccccccaaacaaaccaagggppssswwwwwwyyywvvqqqqqqmmmccccccc
|
||||
abcaaaaaccccaaaaacaaccaaccaaaccaaaaaaaaaaaaaagggppsssswwwswwyywvrqqqqmmmmcccccccc
|
||||
abcaaaaaaccaaaaacccccccccaaaaccaaaaaaaaaacaaagggpppssssssswwwwwwrrqmmmmmccccccccc
|
||||
abcaacaaaccaaaaaaccccccccaaaaccccaaaaaacccaaagggppppssssssrwwwwrrrmmmmmdccccccccc
|
||||
abccccaaaccaaaaaaccccccccaaaaccccaaaaaacccaacggggpooooooosrrwwwrrnmmmddddcacccccc
|
||||
abccccaaaaaaaacccccccccccccccccccaaaaaaaccccccggggoooooooorrrrrrrnnmdddddaaaacccc
|
||||
abcccccaaaaaaccccccccccccccccccccaaacaaacccccccggggfffooooorrrrrrnnddddaaaaaacccc
|
||||
abccaaaaaaaacccccccccccccccccccccaccccccccccccccggffffffooonrrrrnnndddaaaaaaacccc
|
||||
abccaaaaaaaaaccccaacccccccccccccccccccccccccccccccfffffffoonnnnnnndddcaaaaacccccc
|
||||
abccaaaaaaaaaacccaaccccccccccccccaccccccccccccccccccccffffnnnnnnnedddaaaaaacccccc
|
||||
abcccccaaaaaaaaaaaacccccccaccccaaacccccccccccccccccccccfffeennnneeedcccccaacccccc
|
||||
abcccccaaacccaaaaaaaaccccaaacccaaaccacccccccccccccccccccafeeeeeeeeecccccccccccccc
|
||||
abcccccaaccccaaaaaaaaacccaaaaaaaaaaaaccccccaaaccccccccccaaeeeeeeeeeccccccccccccca
|
||||
abaccccccccccaaaaaaaaacccaaaaaaaaaaacccccccaaaaacccccccaaaaceeeeecccccccccccaccca
|
||||
abaccccccccccaaaaaaaaccaaaaaaaaaaaaaacccccaaaaaccccccccaaaccccaaacccccccccccaaaaa
|
||||
abaccccccccccaaaaaaacccaaaaaaaaaaaaaacccccaaaaacccccccccccccccccccccccccccccaaaaa
|
||||
abaccccccccccaccaaaacccaaaaaaaaaaaaaaccccccaaaaaccccccccccccccccccccccccccccaaaaa
|
Loading…
Reference in New Issue