Finished Day 1 of the Advent of Code.

Took me a lot longer to actually program this in python than it should have but eventually got it after reading some of the solutions that I used to make my own. I did learn of how to pull the data from the input.txt file I created with all the values and once I did that it was pretty smooth sailing.

I’ve created a GitHub repo for this where I’ll include all my solutions for each day. I’ve included them below as well.

Problem 1 Solution

with open('input.txt', 'r') as f:
    module_mass = f.readlines()

def fuel_calculator(mass):
    return (int(mass) // 3) - 2

fuel = sum([fuel_calculator(x) for x in module_mass])
print(fuel)

Problem 2 Solution

with open('input.txt', 'r') as f:
module_mass = f.readlines()

def fuel_mass_calculator(mass, extra_fuel=0):
    total_fuel = (mass // 3) - 2
    if total_fuel > 0:
        additional_fuel = extra_fuel + total_fuel
        return fuel_mass_calculator(total_fuel, additional_fuel)
    else:
        return extra_fuel

def total_fuel_calculator(mass):
    base_fuel = (int(mass) // 3) - 2
    extra_fuel = fuel_mass_calculator(base_fuel)
    full_fuel = base_fuel + extra_fuel
    return full_fuel

total_fuel = sum([total_fuel_calculator(x) for x in module_mass])
print(total_fuel)