def main():
    lines = helpers.get_lines(r"../data/day_09.txt")
    db = generate_db(lines)
    low, high = get_shortest_distance(db)

    assert low == 117
    assert high == 909
示例#2
0
def main():
    lines = helpers.get_lines(r"../data/day_19.txt")
    key, db = parse_lines(lines)
    part01 = get_distinct_molecules(key, db)
    assert len(part01) == 535

    part02 = fabricate_molecule(key, db)
    assert part02 == 212
def main():
    lines = helpers.get_lines(r"../data/day_15.txt")
    db = parse_lines(lines)
    part01 = calculate_cookie_score(db)
    assert part01 == 18965440

    part02 = calculate_cookie_score(db, calories=500)
    assert part02 == 15862900
def main():
    lines = helpers.get_lines(r"../data/day_03.txt")
    for line in lines:
        part1 = track_visits([line])
        assert part1 == 2592

        visitors = split_list_into_even_odd_directions(line)
        part2 = track_visits(visitors)
        assert part2 == 2360
def main():
    lines = helpers.get_lines(r"../data/day_13.txt")
    db = create_database(lines)

    happy_bank = get_happiness_results(db)
    part01 = max(happy_bank)
    assert part01 == 733

    db = add_new_guest(db, "Jason", default_change=0)
    happy_bank = get_happiness_results(db)
    part02 = max(happy_bank)
    assert part02 == 725
def main():
    lines = helpers.get_lines(r"../data/day_07.txt")
    parsed = parse_lines(lines)

    values = collect_values(parsed)

    part1 = values["a"]
    assert part1 == 3176

    values = collect_values(parsed, override={"b": part1})
    part2 = values["a"]
    assert part2 == 14710
示例#7
0
def main():
    pattern = r"^(\d+)x(\d+)x(\d+)"
    lines = helpers.get_lines(r"../data/day_02.txt")
    total1 = 0
    total2 = 0
    for line in lines:
        groups = re.search(pattern, line)
        l, w, h = groups.groups()
        total1 += get_area(int(l), int(w), int(h))
        total2 += get_ribbon(int(l), int(w), int(h))

    assert total1 == 1588178
    assert total2 == 3783758
def main():
    instructions = helpers.get_lines(r"../data/day_23.txt")

    # Part01
    result_registers = process_instructions(instructions)
    assert result_registers["b"] == 255

    # Part02
    # - reset registers
    registers["a"] = 1
    registers["b"] = 0
    result_registers = process_instructions(instructions)
    assert result_registers["b"] == 334
def main():
    lines = helpers.get_lines(r"../data/day_05.txt")
    part1 = 0
    part2 = 0

    for line in lines:
        if is_naughty_or_nice_part1(line) is True:
            part1 += 1
        if is_naughty_or_nice_part2(line) is True:
            part2 += 1

    assert part1 == 255
    assert part2 == 55
示例#10
0
def main():
    lines = helpers.get_lines(r"../data/day_18.txt")
    grid = get_grid(lines)

    for _ in range(100):
        grid = flip(grid)
    part01 = sum([g.count("#") for g in grid])
    assert part01 == 821

    grid = get_grid(lines, corners_always_on=True)
    for _ in range(100):
        grid = flip(grid, corners_always_on=True)
    part02 = sum([g.count("#") for g in grid])
    assert part02 == 886
示例#11
0
def main():
    lines = helpers.get_lines(r"../data/day_08.txt")
    t_code = 0
    t_char = 0
    t_enco = 0
    for line in lines:
        code, char, enco = get_code_and_characters(line)
        t_code += code
        t_char += char
        t_enco += enco
    part1 = t_code - t_char
    part2 = t_enco

    assert part1 == 1350
    assert part2 == 2085
示例#12
0
def main():
    lines = helpers.get_lines(r"../data/day_24.txt")
    nums = [int(n) for n in lines]

    magic_number = (
        6
    )  # was the smallest brute force that would generate the balanced number
    buckets = 3  # from instructions -- need three equal weighted buckets
    part_01_results = get_smallest_quantum_entanglement_bucket(
        buckets, magic_number, nums)
    assert min(part_01_results) == 10439961859

    magic_number = 5  # brute forced this minimum number that makes up the value
    buckets = 4  # from instructions
    part_02_results = get_smallest_quantum_entanglement_bucket(
        buckets, magic_number, nums)
    assert min(part_02_results) == 72050269
示例#13
0
def main():
    lines = helpers.get_lines(r"../data/day_17.txt")
    items = [int(l) for l in lines]
    buckets = get_buckets(items, 150)
    part01 = len(buckets)
    assert part01 == 1304

    # find the smallest sized grouping
    smallest_size = 1_000_000
    for b in buckets:
        if len(b) < smallest_size:
            smallest_size = len(b)

    # Collect and count the number of buckets using the smallest size
    part02 = len([b for b in buckets if len(b) == smallest_size])

    assert part02 == 18
示例#14
0
    def get_instructions(self):
        pattern = re.compile(r"^.* (\d+),(\d+) through (\d+),(\d+)")

        lines = helpers.get_lines(r"../data/day_06.txt")
        for line in lines:
            items = [None, None, None]

            info = line.strip().split()

            if "off" in info:
                items[0] = False
            elif "on" in info:
                items[0] = True
            elif "toggle" in info:
                items[0] = "toggle"

            matches = re.match(pattern, line)
            items[1] = (int(matches.group(1)), int(matches.group(2)))
            items[2] = (int(matches.group(3)), int(matches.group(4)))

            self.instructions.append(items)
示例#15
0
def main():
    lines = helpers.get_lines(r"../data/day_14.txt")

    cycles = {c[0]: cycle(*c[1:]) for c in parse_lines(lines)}
    part01_results = {k: 0 for k in cycles.keys()}
    part02_results = {k: 0 for k in cycles.keys()}

    magic_cycle_number = 2503
    for t in range(magic_cycle_number):
        for k, v in cycles.items():
            # Calculate overall distance scores
            part01_results[k] += next(v)

        current_lead_score = max(part01_results.values())
        for k2, v2 in part01_results.items():
            if v2 == current_lead_score:
                part02_results[k2] += 1

    part01 = max(part01_results.values())
    assert part01 == 2696

    part02 = max(part02_results.values())
    assert part02 == 1084
示例#16
0
def main():
    lines = helpers.get_lines(r"../data/day_16.txt")
    db = parse_lines(lines)

    rules = {
        "children": 3,
        "cats": 7,
        "samoyeds": 2,
        "pomeranians": 3,
        "akitas": 0,
        "vizslas": 0,
        "goldfish": 5,
        "trees": 3,
        "cars": 2,
        "perfumes": 1,
    }

    possibles = mfcsam(db, rules)
    part01 = possibles.index(max(possibles)) + 1
    assert part01 == 373

    possibles2 = mfcsam(db, rules, exact=False)
    part02 = possibles2.index(max(possibles2)) + 1
    assert part02 == 260
示例#17
0
def main():
    lines = helpers.get_lines(r"../data/day_01.txt")
    part1 = get_floor(lines)
    part2 = get_floor(lines, -1)
    assert part1 == 232
    assert part2 == 1783