Exemple #1
0
def main():
    rows = [int(row.strip()) for row in file_to_lines("inputs/day09.txt")]
    # print(first(rows))

    cProfile.run('test()')
    print(first(rows))
    test()
Exemple #2
0
def main():
    # sorting is really useful in this one
    rows = sorted([int(x) for x in file_to_lines("inputs/day10.txt")])
    print(first(rows))
    import time

    start = time.perf_counter()
    print(second(rows))
    end = time.perf_counter()
    print(end - start)
Exemple #3
0
def main():
    rows = file_to_lines("inputs/day17.txt")
    active_cells: Set[Vector] = set()
    for y, row in enumerate(rows):
        for x, value in enumerate(row.strip()):
            if value == "#":
                active_cells.add((x, y, 0, 0))

    print(run(active_cells))
    print(run(active_cells, use_fourth_dim=True))
Exemple #4
0
def test():
    results = []
    n_runs = 1000
    rows = [int(row.strip()) for row in file_to_lines("inputs/day09.txt")]
    for _ in range(n_runs):
        start = time.perf_counter()
        first(rows)
        stop = time.perf_counter()
        results.append((stop - start))
    print(sum(results) / n_runs)
Exemple #5
0
def main():
    rows = file_to_lines("inputs/day13.txt")
    print(first(rows))
    print(second(rows))
Exemple #6
0
def main():
    rows = file_to_lines('inputs/day01.txt')
    numbers = get_2_numbers(rows)
    print(numbers[0] * numbers[1] )
Exemple #7
0
def compute_addition(problem):
    problem = problem.strip("()")
    while "+" in problem:
        enclosed_groups = re.findall(r"\d+ \+ \d+", problem)
        for group in enclosed_groups:
            numbers = re.findall(r"\d+", group)
            group_result = sum(int(n) for n in numbers)
            problem = f"{group_result}".join(problem.split(group))
    return compute_multiplication(problem)


def compute_parens(problem, left_to_right=False):
    while "(" in problem:
        enclosed_groups = re.findall(r"\([\d\+\*\s]+\)", problem)
        for group in enclosed_groups:
            if left_to_right:
                group_result = compute_enclosed_group_left_to_right(group)
            else:
                group_result = compute_addition(group)
            problem = f"{group_result}".join(problem.split(group))

    if left_to_right:
        return compute_enclosed_group_left_to_right(problem)
    return compute_addition(problem)


rows = file_to_lines("inputs/day18.txt")
print(sum(int(compute_parens(row, left_to_right=True)) for row in rows))
print(sum(int(compute_parens(row)) for row in rows))
Exemple #8
0
def main():
    rows = [(row[0], int(row[1:].strip()))
            for row in file_to_lines("inputs/day12.txt")]
    print(first(rows))
    print(second(rows))
Exemple #9
0
def main():
    paths = file_to_lines("inputs/day24.txt")
    print(first(paths))
    print(second(paths))
Exemple #10
0
def main():
    rows = file_to_lines("inputs/day04.txt", separate_with_empty=True)
    print(first(rows))
    print(second(rows))
Exemple #11
0
def main():
    rows = [
        parse_line_to_instr(line) for line in file_to_lines("inputs/day08.txt")
    ]
    print(first(rows))
    print(second(rows))
Exemple #12
0
def main():
    rows = [list(line.strip()) for line in file_to_lines("inputs/day11.txt")]
    print(first(rows))
    print(second(rows))