def calc_fuel_requirement_addl():

    modules = common.listify_input_file('01-input.txt')

    total = 0
    for module in modules:
        total += calc_fuel(int(module))

    return total
Exemple #2
0
def do_part_2():
    """ Which asteroid is the 200th to be vaporized? """

    graph = common.listify_input_file("10-input.txt")
    asteroids = list(make_asteroids(graph))
    monitor = 17 + 22j  # answer from part 1
    vaporized = vaporize_asteroids(monitor, asteroids)

    return vaporized[199]
Exemple #3
0
def do_part_1():
    """ Which asteroid can see the most other asteroids? """

    graph = common.listify_input_file("10-input.txt")
    asteroids = {asteroid: None for asteroid in make_asteroids(graph)}

    for asteroid in asteroids:
        asteroids[asteroid] = get_unique_slopes(asteroid, asteroids)

    return len(max(asteroids.items(), key=lambda item: len(item[1]))[1])
def calc_fuel_requirement():
    # if mass < 6 ??

    masses = common.listify_input_file('01-input.txt')

    total = 0
    for mass in masses:
        total += int(mass) // 3 - 2

    return total
    fewest_x = None
    for x in x_set:
        if x == 0 + 0j:
            continue
        x_steps = get_coordinate_index(wire0, x) + get_coordinate_index(
            wire1, x)
        if x_steps < steps:
            fewest_x = x
        steps = min(x_steps, steps)

    return (fewest_x, steps)


#########
if __name__ == '__main__':
    wires = cmn.listify_input_file('03-input.txt')

    wire0 = Wire(wires[0])
    wire0._make_coords()
    wire1 = Wire(wires[1])
    wire1._make_coords()
    print("test1:", get_closest_intersection(wire1, wire0))
    print("test2:", get_fewest_steps_intersection(wire1, wire0))

    wire0 = Wire(wires[-1])
    wire0._make_coords()
    wire1 = Wire(wires[-2])
    wire1._make_coords()

    print("Part 1:", get_closest_intersection(wire1, wire0))
    print("Part 2:", get_fewest_steps_intersection(wire1, wire0))
Exemple #6
0
"""

from copy import deepcopy
import common

TEST_INPUT = [
    "COM)B", "B)C", "C)D", "D)E", "E)F", "B)G", "G)H", "D)I", "E)J", "J)K",
    "K)L"
]

TEST2_INPUT = [
    "COM)B", "B)C", "C)D", "D)E", "E)F", "B)G", "G)H", "D)I", "E)J", "J)K",
    "K)L", "K)YOU", "I)SAN"
]

PUZZ_INPUT = common.listify_input_file("06-input.txt")


class Node(object):
    def __init__(self, data):
        self.data = data
        self.children = []

    def __repr__(self):
        return "<Node " + self.data + " children: " + str(len(
            self.children)) + ">"


def make_paths(pairs):

    nodes = {}
    lower_bound = 469536  # assume ore needed for 1 fuel is good lower bound

    while lower_bound + 1 != upper_bound:
        if upper_bound is None:
            guess = lower_bound * 2
        else:
            guess = (upper_bound + lower_bound) // 2

        ore_needed = calc_ore_needed(guess, recipes)
        if ore_needed > ore:
            upper_bound = guess
        else:
            lower_bound = guess

    return lower_bound


##########
if __name__ == "__main__":
    test_recipes_1 = build_recipes((TEST_INPUT_1))
    test_recipes_2 = build_recipes((TEST_INPUT_2))
    test_recipes_3 = build_recipes((TEST_INPUT_3))
    assert calc_ore_needed(1, test_recipes_1) == 31
    assert calc_ore_needed(1, test_recipes_2) == 165
    assert calc_ore_needed(1, test_recipes_3) == 13312

    recipes = build_recipes(cmn.listify_input_file("14-input.txt"))
    print(f"Part 1: {calc_ore_needed(1, recipes)}")  # answer 469536
    print(f"Part 2: {calc_fuel_given_ore(1000000000000, recipes)}"
          )  # answer 3343477