Last active
December 2, 2019 06:29
-
-
Save h3matite/107bca58e9f82d7ee475797a7c4f493c to your computer and use it in GitHub Desktop.
Advent of Code Day 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_fuel(mass): | |
return (int(mass.strip()) // 3) - 2 | |
## Load Data | |
with open("input.txt", "r") as f: | |
module_weights = f.readlines() | |
## Find Required Fuel | |
fuel = sum([calc_fuel(x) for x in module_weights]) | |
print("Day1, Part1 --", fuel) | |
# | |
# | |
# | |
# | |
# ## Verbose Original: | |
# def get_fuel_from_masses(masses): | |
# fuel = 0 | |
# for mass in masses: | |
# fuel += (mass // 3) - 2 | |
# return fuel | |
# | |
# if __name__ == '__main__': | |
# | |
# ## Init / Load Data | |
# module_weights = [] | |
# with open("input.txt", "r") as f: | |
# module_weights = f.readlines() | |
# | |
# ## Format Data | |
# module_weights = [int(x.strip()) for x in module_weights] | |
# | |
# ## Find Required Fuel | |
# fuel = get_fuel_from_masses(module_weights) | |
# print("Part1 --", fuel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_fuel_from_fuel_mass(mass, extra_fuel=0): | |
new_weight_fuel = (mass // 3) - 2 | |
if new_weight_fuel > 0: | |
out_fuel = extra_fuel + new_weight_fuel | |
return get_fuel_from_fuel_mass(new_weight_fuel, out_fuel) | |
else: | |
return extra_fuel | |
def calc_fuel(mass): | |
base_fuel = (int(mass.strip()) // 3) - 2 | |
extra_fuel = get_fuel_from_fuel_mass(base_fuel) | |
full_fuel = base_fuel + extra_fuel | |
return full_fuel | |
## Load Data | |
with open("input.txt", "r") as f: | |
module_weights = f.readlines() | |
## Find Required Fuel | |
fuel = sum([calc_fuel(x) for x in module_weights]) | |
print("Day1, Part2 --", fuel) | |
# | |
# | |
# | |
# | |
# ## Verbose Original: | |
# def get_fuel_from_fuel_mass(mass, extra_fuel): | |
# new_weight_fuel = (mass // 3) - 2 | |
# if new_weight_fuel > 0: | |
# out_fuel = extra_fuel + new_weight_fuel | |
# return get_fuel_from_fuel_mass(new_weight_fuel, out_fuel) | |
# else: | |
# return extra_fuel | |
# | |
# def get_fuel_from_masses(masses): | |
# fuel_list = [] | |
# for mass in masses: | |
# base_fuel = (mass // 3) - 2 | |
# extra_fuel = get_fuel_from_fuel_mass(base_fuel, 0) | |
# full_fuel = base_fuel + extra_fuel | |
# fuel_list.append(full_fuel) | |
# return fuel_list | |
# | |
# if __name__ == '__main__': | |
# | |
# ## Init / Load Data | |
# module_weights = [] | |
# with open("input.txt", "r") as f: | |
# module_weights = f.readlines() | |
# | |
# ## Format Data | |
# module_weights = [int(x.strip()) for x in module_weights] | |
# | |
# ## Find Required Fuel | |
# final_fuel_list = get_fuel_from_masses(module_weights) | |
# print("Part2", sum(final_fuel_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment