This commit is contained in:
Tyrel Souza 2022-12-12 13:38:46 -05:00
parent b87c69bd17
commit a7578c2bc2
2 changed files with 18 additions and 7 deletions

View File

@ -60,7 +60,11 @@ def part2(mx):
pass pass
shortest = min(paths, key= lambda x: x.total_cost) 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.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) print(shortest.total_cost)

View File

@ -15,6 +15,7 @@ class colors:
YELLOW = "\033[93m" YELLOW = "\033[93m"
RED = "\033[91m" RED = "\033[91m"
ENDC = "\033[0m" ENDC = "\033[0m"
BLINK = "\033[5m"
def apply_to_all(mx, func): 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])) 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 print a matrix of anything, Falsy values turns to `.` for clarity
""" """
mx = deepcopy(matrix) mx = deepcopy(matrix)
for (y, x) in red: for (y, x) in red:
try: if (y,x) in blue or (y,x) in green or (y,x) in blink_green:
new = f"{colors.RED}{mx[y][x]}{colors.ENDC}" continue
mx[y][x] = new new = f"{colors.RED}{mx[y][x]}{colors.ENDC}"
except IndexError: mx[y][x] = new
breakpoint()
for (y, x) in green: 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}" new = f"{colors.GREEN}{mx[y][x]}{colors.ENDC}"
mx[y][x] = new mx[y][x] = new
for (y, x) in blue: for (y, x) in blue:
if (y,x) in blink_green:
continue
new = f"{colors.BLUE}{mx[y][x]}{colors.ENDC}" new = f"{colors.BLUE}{mx[y][x]}{colors.ENDC}"
mx[y][x] = new 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') ppmx(mx, pad=False, space=True, zero='0')