Beispiel #1
0
def test_part2_total():
    modules = [Part2Module(mass) for mass in get_input_data(1)]
    assert get_total_mass(modules) == 4903759
Beispiel #2
0
def test_part1_total():
    modules = [Part1Module(mass) for mass in get_input_data(1)]
    assert get_total_mass(modules) == 3271095
Beispiel #3
0
from functools import reduce

from aoc.util.data import get_input_data
from aoc.day3.part1 import Panel as Part1Panel, Wire as Part1Wire, Point


class Wire(Part1Wire):
    def get_point_index(self, point: Point):
        return self.points.index(point)


class Panel(Part1Panel):
    def __init__(self, wire1: Wire, wire2: Wire):
        super().__init__(wire1, wire2)

    def get_combined_length(self, point: Point):
        return self.wire1.get_point_index(point) + self.wire2.get_point_index(
            point) + 2

    def get_shortest_crossing_path(self):
        return min(self.get_combined_length(x) for x in self.get_crossings())


if __name__ == "__main__":
    line1, line2 = get_input_data(3)
    wire1, wire2 = Wire(line1), Wire(line2)
    panel = Panel(wire1, wire2)
    print(panel.get_shortest_crossing_path())
Beispiel #4
0
So, for each module mass, calculate its fuel and add it to the total. Then, treat the fuel amount
you just calculated as the input mass and repeat the process, continuing until a fuel requirement is
zero or negative. For example:

A module of mass 14 requires 2 fuel. This fuel requires no further fuel (2 divided by 3 and rounded
down is 0, which would call for a negative fuel), so the total fuel required is still just 2.
At first, a module of mass 1969 requires 654 fuel. Then, this fuel requires 216 more fuel
(654 / 3 - 2). 216 then requires 70 more fuel, which requires 21 fuel, which requires 5 fuel, which
requires no further fuel. So, the total fuel required for a module of mass
1969 is 654 + 216 + 70 + 21 + 5 = 966. The fuel required by a module of mass 100756 and its fuel is:
33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346.

What is the sum of the fuel requirements for all of the modules on your spacecraft when also taking
into account the mass of the added fuel? (Calculate the fuel requirements for each module
separately, then add them all up at the end.)
"""
from aoc.util.data import get_input_data
from aoc.day1.part1 import Module as Part1Module, get_total_mass


class Module(Part1Module):
    @property
    def fuel(self) -> int:
        required = super().fuel
        return 0 if required <= 0 else required + Module(required).fuel


if __name__ == "__main__":
    masses = get_input_data(1)
    print(get_total_mass([Module(mass) for mass in masses]))
Beispiel #5
0
def test_part2_result():
    line1, line2 = get_input_data(3)
    wire1, wire2 = Part2Wire(line1), Part2Wire(line2)
    panel = Part2Panel(wire1, wire2)
    assert panel.get_shortest_crossing_path() == 10554
Beispiel #6
0
def test_part1_result():
    line1, line2 = get_input_data(3)
    wire1, wire2 = Wire(line1), Wire(line2)
    panel = Panel(wire1, wire2)
    assert panel.get_closest_crossing().manhattan_distance == 280