more fun
This commit is contained in:
parent
b87c69bd17
commit
a7578c2bc2
@ -60,7 +60,11 @@ def part2(mx):
|
||||
pass
|
||||
shortest = min(paths, key= lambda x: x.total_cost)
|
||||
matrix.apply_to_all(mx, lambda x: chr(x+ord('a'))) # Back to letters, single char prettier
|
||||
matrix.highlight(mx, red=shortest.nodes)
|
||||
all_visited = []
|
||||
for p in paths:
|
||||
all_visited.extend(p.nodes)
|
||||
all_visited = list(set(all_visited))
|
||||
matrix.highlight(mx, red=all_visited, blink_green=shortest.nodes)
|
||||
print(shortest.total_cost)
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@ class colors:
|
||||
YELLOW = "\033[93m"
|
||||
RED = "\033[91m"
|
||||
ENDC = "\033[0m"
|
||||
BLINK = "\033[5m"
|
||||
|
||||
|
||||
def apply_to_all(mx, func):
|
||||
@ -261,21 +262,27 @@ def ppmx(*matrices, pad=True, space=True, zero='.'):
|
||||
print("".join([f(x) for x in c]))
|
||||
|
||||
|
||||
def highlight(matrix, red=[], green=[], blue=[]):
|
||||
def highlight(matrix, red=[], green=[], blue=[], blink_green=[]):
|
||||
"""
|
||||
print a matrix of anything, Falsy values turns to `.` for clarity
|
||||
"""
|
||||
mx = deepcopy(matrix)
|
||||
for (y, x) in red:
|
||||
try:
|
||||
if (y,x) in blue or (y,x) in green or (y,x) in blink_green:
|
||||
continue
|
||||
new = f"{colors.RED}{mx[y][x]}{colors.ENDC}"
|
||||
mx[y][x] = new
|
||||
except IndexError:
|
||||
breakpoint()
|
||||
for (y, x) in green:
|
||||
if (y,x) in blue or (y,x) in blink_green:
|
||||
continue
|
||||
new = f"{colors.GREEN}{mx[y][x]}{colors.ENDC}"
|
||||
mx[y][x] = new
|
||||
for (y, x) in blue:
|
||||
if (y,x) in blink_green:
|
||||
continue
|
||||
new = f"{colors.BLUE}{mx[y][x]}{colors.ENDC}"
|
||||
mx[y][x] = new
|
||||
for (y, x) in blink_green:
|
||||
new = f"{colors.BLINK}{colors.GREEN}{mx[y][x]}{colors.ENDC}"
|
||||
mx[y][x] = new
|
||||
ppmx(mx, pad=False, space=True, zero='0')
|
||||
|
Loading…
Reference in New Issue
Block a user