コード例 #1
0
ファイル: solution.py プロジェクト: ccharles/AdventCode
def calculate_additional_fuel(initial_fuel):
    """
    Recursively calculate the amount of fuel required to carry the fuel.
    Of course it could be done without the recursion
    but I have decided to show off
    :param initial_fuel: the amount of fuel needed to carry
    :return: the amount of fuel needed for carrying the initial fuel tank
    """
    additional_fuel = calculate_fuel(initial_fuel)
    if additional_fuel <= 0:
        return 0
    else:
        return additional_fuel + calculate_additional_fuel(additional_fuel)
コード例 #2
0
ファイル: solution.py プロジェクト: ccharles/AdventCode
def solution():
    from pathlib import Path
    input_file = Path(INPUT_FILE)

    fuel_sum = 0
    with open(input_file, 'r') as puzzle_input:
        for line in puzzle_input:
            payload_fuel = calculate_fuel(line)
            fuel_for_fuel = calculate_additional_fuel(payload_fuel)

            fuel_sum += (payload_fuel + fuel_for_fuel)

    return fuel_sum
コード例 #3
0
ファイル: test_day_1.py プロジェクト: rsdavies/advent-of-code
def test_2():
    assert calculate_fuel(14) == 2
コード例 #4
0
ファイル: test_day_1.py プロジェクト: rsdavies/advent-of-code
def test_1():
    assert calculate_fuel(12) == 2
コード例 #5
0
ファイル: test_day_1.py プロジェクト: rsdavies/advent-of-code
def test_4():
    assert calculate_fuel(100756) == 50346
コード例 #6
0
ファイル: test_day_1.py プロジェクト: rsdavies/advent-of-code
def test_3():
    assert calculate_fuel(1969) == 966