<jupyter_start><jupyter_text>Day 15: Chiton part 1:* given a map of risk levels, find the route from top to bottom with the lowest possible risk level* score is accumulated as a postiion is entered, so the starting position does not count<jupyter_code>from heapq import heappush, heappop
import copy
from collections import defaultdict
with open("input") as f:
    risk_scores = list(map(lambda n: [int(x) for x in list(n.strip())], f.readlines()))
def get_adj(x, y, grid):
    w = len(grid[0])
    l = len(grid)
    vals = []
    
    for x1, y1 in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        if 0 <= x + x1 < w and 0 <= y + y1 < l:
            vals.append(((y + y1),(x + x1)))

    return vals
def dijkstra(graph):
    w = len(graph[0])
    l = len(graph)
    
    distance = [[float('inf') for n in range(len(graph[0]))] for m in range(len(graph))]
    distance[0][0] = 0
    
    queue = {(y, x) for y in range(l) for x in range(w)}
    
    while len(queue) > 0:
        y, x = min(queue, key=lambda z: distance[z[0]][z[1]])
        queue.remove((y, x))
        
        for y1, x1 in get_adj(x, y, graph):
            alt = distance[y][x] + graph[y1][x1]
            if alt < distance[y1][x1]:
                distance[y1][x1] = alt
                
    return distance
print('part 1: ', dijkstra(risk_scores)[-1][-1])<jupyter_output>part 1:  503<jupyter_text>part 2* the cave is actually 5x larger than we though, the area scanned is one tile in a 5x5 area that forms the full map* each time a tile repeats right and down, its risk increases by 1, until it raches 9, then it wraps around to 1* what is the best path through the full map?<jupyter_code>def extend_cave(cave, cave_repeats):
    for line in cave:
        new_line = []
        for inc in range(cave_repeats-1):
            new_line += [(val + inc) % 9 + 1 for val in line]
        line.extend(new_line)

    new_rows = []
    for inc in range(cave_repeats-1):
        new_nums = []
        for line in cave:
            new_line = []
            for val in line:
                new_line.append((val + inc) % 9 + 1)
            new_nums.append(new_line)
        new_rows.extend(new_nums)
    cave.extend(new_rows)
    
    return cave
full_risk_scores = extend_cave(risk_scores, 5)
print('part 2: ', dijkstra(full_risk_scores)[-1][-1])<jupyter_output>part 2: 2853
{'fraction_non_alphanumeric': 0.1277325332190313, 'fraction_numerical': 0.02786112301757394, 'mean_word_length': 2.585253456221198, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '140753', 'license': 'MIT', 'n_tokens_mistral': 870, 'n_tokens_neox': 818, 'n_words': 270, 'path': 'day15/solution.ipynb', 'repo_name': 'caseyjellis/adventofcode_2021', 'size': '2333'}