Exemplo n.º 1
0
def run_part_2():
    depths = {
        int(k): int(v)
        for k, v in advent_tools.dict_from_input_file(':').items()
    }
    count = 1
    while True:
        if all(
                scanner_pos(depth, count + layer) != 0
                for layer, depth in depths.items()):
            return count
        count = count + 1
Exemplo n.º 2
0
 def __init__(self):
     super().__init__((20, 91))
     self.depth = {
         int(k): int(v)
         for k, v in advent_tools.dict_from_input_file(':').items()
     }
     # super().__init__((5, 7))
     # self.depth = {0: 3, 1: 2, 4: 4, 6: 4}
     self.directions = {}
     self.positions = {}
     for k, v in self.depth.items():
         self.grid[0:v, k] = 1
         self.grid[0, k] = 2
         self.positions[k] = 0
         self.directions[k] = 1
     self.layer = 0
Exemplo n.º 3
0
def run_generations(init_state, num_gen):
    buffer = num_gen * 2
    state = '.' * buffer + init_state + '.' * buffer
    numbers = range(-buffer, len(init_state) + buffer)
    maps = advent_tools.dict_from_input_file()
    totals = []
    for _ in range(num_gen):
        new_state = '...'
        for i in range(3, len(state) - 3):
            local_state = state[i - 2:i + 3]
            new_state = new_state + maps[local_state]
        state = new_state + '...'
        total = sum(num if plant == '#' else 0
                    for num, plant in zip(numbers, state))
        totals.append(total)
    return totals
Exemplo n.º 4
0
def iterate_fractal(num_iterations=18):
    pattern_map = advent_tools.dict_from_input_file()
    init_pattern = '.#./..#/###'
    cur_grid = convert_pattern_to_grid(init_pattern)
    for _ in range(num_iterations):
        sub_grids = break_up_grid(cur_grid)
        new_subs = []
        for sub_grid in sub_grids:
            possible_grids = equivalent_grids(sub_grid)
            possible_patterns = [
                convert_grid_to_pattern(grid) for grid in possible_grids
            ]
            for pattern in possible_patterns:
                if pattern in pattern_map:
                    new_pattern = pattern_map[pattern]
                    break
            new_subs.append(convert_pattern_to_grid(new_pattern))
        cur_grid = assemble_subgrids(new_subs)
        print(_)
        # plt.imshow(cur_grid)
        # plt.show()
    return cur_grid.sum().sum()
Exemplo n.º 5
0
def read_data():
    data2 = advent_tools.dict_from_input_file('<->')
    data = {}
    for k, v in data2.items():
        data[int(k)] = [int(num) for num in v.split(',')]
    return data