diff --git a/2022/python/day12.py b/2022/python/day12.py index 4309b0c..95c8189 100644 --- a/2022/python/day12.py +++ b/2022/python/day12.py @@ -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) diff --git a/2022/python/matrix.py b/2022/python/matrix.py index dc6c9ad..3c4f716 100644 --- a/2022/python/matrix.py +++ b/2022/python/matrix.py @@ -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: - new = f"{colors.RED}{mx[y][x]}{colors.ENDC}" - mx[y][x] = new - except IndexError: - breakpoint() + 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 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')