Example #1
0
def run_part_1():
    lines = advent_tools.read_all_integers()
    grid = np.zeros((1000, 1000))
    for elf_num, x, y, width, height in lines:
        grid[x:x + width, y:y + height] = grid[x:x + width, y:y + height] + 1
    plt.imshow(grid)
    plt.show()
    return (grid > 1).sum().sum()
Example #2
0
def run_part_1():
    data = advent_tools.read_all_integers()
    # first_steps = 9800
    # last_steps = 10200
    first_steps = 10020
    last_steps = 10030
    for steps in range(first_steps, last_steps):
        show_grid(data, steps)
Example #3
0
def run_part_2():
    stuff = [num[0] for num in advent_tools.read_all_integers()]
    recorded = {0}
    summed = 0
    for num in itertools.cycle(stuff):
        summed += num
        if summed in recorded:
            return summed
        recorded.add(summed)
Example #4
0
def run_part_2():
    lines = advent_tools.read_all_integers()
    grid = np.zeros((1000, 1000))
    for elf_num, x, y, width, height in lines:
        grid[x:x + width, y:y + height] = grid[x:x + width, y:y + height] + 1
    for elf_num, x, y, width, height in lines:
        max_num = grid[x:x + width, y:y + height].max().max()
        if max_num == 1:
            return elf_num
Example #5
0
def run_part_1():
    particles = advent_tools.read_all_integers()
    result = []
    for _ in range(1000):
        take_one_step(particles)
        distances = [
            abs(part[0]) + abs(part[1]) + abs(part[2]) for part in particles
        ]
        result.append(np.argmin(distances))
    return result[-1]
Example #6
0
def run_part_2():
    particles = advent_tools.read_all_integers()
    for _ in range(40):
        marked = set()
        for index1 in range(len(particles)):
            for index2 in range(index1 + 1, len(particles)):
                if particles[index1][:3] == particles[index2][:3]:
                    marked.add(index1)
                    marked.add(index2)
        particles = [
            part for index, part in enumerate(particles) if index not in marked
        ]
        take_one_step(particles)
    return len(particles)
Example #7
0
def run_part_2():
    data = advent_tools.read_all_integers()[0]
    return process_node_part_two(data, 0)
Example #8
0
def run_part_1():
    stuff = [num[0] for num in advent_tools.read_all_integers()]
    return sum(stuff)
Example #9
0
def run_part_2():
    ports = advent_tools.read_all_integers()
    cur_port = 0
    return score_part_2(cur_port, ports)
Example #10
0
import advent_tools


def memory_game(starting_numbers, end):
    number = 0
    last_called = {n: i for i, n in enumerate(starting_numbers[:-1])}
    prev_number = starting_numbers[-1]
    for turn in range(len(starting_numbers), end):
        try:
            last_turn = last_called[prev_number]
        except KeyError:
            number = 0
        else:
            number = turn - last_turn - 1
        last_called[prev_number] = turn - 1
        prev_number = number
    return number


def run_part_1(starting_numbers):
    return memory_game(starting_numbers, 2020)


def run_part_2(starting_numbers):
    return memory_game(starting_numbers, 30000000)


if __name__ == '__main__':
    data = advent_tools.read_all_integers()[0]
    print('Part 1:', run_part_1(data))
    print('Part 2:', run_part_2(data))